Comment by pjmlp

1 day ago

Sure, here is some C++23 code

Some forced example, combining ranges with type deduction for collection types and simplified print, for a C++ version of using itertools.

    int main() {
        std::array values = {1, 545, 46, 23, 45, 102, 57};
        fmt::println("Original value set {}", values);

        auto some = values | views::take (2);
        fmt::println("Take some elements {}", some);

        auto squares = values | views::transform([](auto x) { return x * x;});
        fmt::println("Squares the elements {}", squares);    

        auto even = values | views::filter([](auto x) { return x % 2 == 0;});
        fmt::println("Get the even elements {}", even);    
    }

Full example at https://godbolt.org/z/5YcoM1WsY

There you will see the comments why fmt and not std, just because of current compiler support, hence why I said on my previous comment, C++20 is still the best supported one currently.

Thank you very much for these examples!

Especially ranges and views are two of my favorite features I'm looking forward to use more.