The C++20 std::views::take and std::views::take_while produce views of the leading elements of the adapted range. Additionally, std::views::take is optimized for random access ranges and will not introduce any overhead for std::span, std::string_view, std::views::iota, std::views::repeat and std::ranges::subrange (if it models random_access and sized). Compiler Explorer link: https://lnkd.in/emMCi2T3 #cpp #cplusplus #coding #programming #dailybiteofcpp
I feel like I need to just start reading the standard library a bit every day to see what’s there. There might be a bunch of things I write myself and know about it.
ranges and views are to C++20 like what algorithms where to C++98-C++11. We do not have to worry about the iterator pairs The more we learn about ranges and views the better C++ programmers we become.
Thanks, these concise but to the point snippets are very helpful.
University of Louisiana at…•2K followers
2yOh my god, wait, this example you just gave literally fixes something I do every day!