4 ms·
Are you aware of ranges? std::ranges::any_of(numbers, [](auto i){ return i % 2 == 0; })) There's also stuff like this for orthogonality https://en.cpprefere
by eska 5y ago
Are you aware of ranges?
std::ranges::any_of(numbers, [](auto i){ return i % 2 == 0; }))
There's also stuff like this for orthogonality https://en.cppreference.com/w/cpp/ranges/transform_view https://en.cppreference.com/w/cpp/ranges/transform_view
- kragen 5y agoYes, which is why I complained about how nonorthogonal the C++ was instead of just how verbose :)
- eska 5y agoSee my edit. You're probably interested in views, with which you can do stuff similar to lazy functional languages v | std::views::reverse | std::views::drop(2); Here's an intro https://hannes.hauswedell.net/post/2019/11/30/range_intro/ https://hannes.hauswedell.net/post/2019/11/30/range_intro/
- blt 5y agoSadly the C++20 ranges library does not include any facility to create views by writing Python-like generator loops (coroutine loops with "yield"). Creating new views is about as difficult as creating iterators before - i.e. too difficult.
- eska 5y agoThen your complaint is not orthogonality. Orthogonality means that you can use a for each loop, find_if, any_of, ranges::any_of and everything will still compose the same no matter where the data comes from (file, network, a function that advances an iterator). Your complaint seems to be that iterators instead of coroutines are used here.