7 ms·
For list comprehension, we have (C++23): `std::ranges::to<std::vector>(items | std::views::filter(shouldInclude) | std::views::transform(f))` it’s not quite `[f
by BenFrantzDale 3y ago
For list comprehension, we have (C++23): `std::ranges::to<std::vector>(items | std::views::filter(shouldInclude) | std::views::transform(f))` it’s not quite `[f(x) for x in items if shouldInclude(x)]` but it’s the same idea.
- nuancebydefault 3y agoTo be honest, if that's the notation, i will not be very eager to jump on cpp23. That said, I admire people who's minds stay open for c++ improvements and make that effort.
- logicchains 3y agoWell you could write it as to<vector>(items | filter(shouldInclude) | transform(f)) if you really want to, but generally C++ programmers prefer to be explicit and include the namespaces.
- xmonkee 3y ago>but generally C++ programmers prefer to be explicit and include the namespaces. why, though? Collisions in the stdlib? stdlib is too new to not be the default for these names?
- Kamq 3y agoThe using declaration modifies your namespace. From the docs: namespace X { using ::f; // global f is now visible as ::X::f using A::g; // A::g is now visible as ::X::g } void h() { X::f(); // calls ::f X::g(); // calls A::g } Link to docs: https://en.cppreference.com/w/cpp/language/namespace#Using-directives https://en.cppreference.com/w/cpp/language/namespace#Using-d...
- xmonkee 3y agoThanks
- Tommstein 3y agoSweet baby Jesus I thought that was a joke as I started reading it. Still not entirely sure.