A library for C++20 that introduced std::ranges namespace, which consists of rangified algorithms from header and of range adaptors divided into views and actions.
I am fairly new to ranges, and I wanted to know if there was a way to apply a dynamic number of range adaptors. I have fiddled around with some code for a while, and I have also done some searching, but to no avail.
#include
#include…
How do I join two views using std::ranges?
In ranges-v3 the views are joined with views::concat(), and I cannot figure out how to do that with std::ranges.
#include
#include
#include
#include
using namespace…
There are four pair-like types in the standard, namely std::array, std::pair, std::tuple, and ranges::subrange, where the overload of std::get for ranges::subrange is defined in [range.subrange#access-10]:
template
I am trying to insert a transformed range of directory entries into a vector using its insert(const_iterator pos, InputIt first, InputIt last) member function template.
Unfortunately I can't get the following code to compile under GCC 11.1.0, which…
Since C++23, views are no longer required to be default_constructible. For range adaptors such as views::filter and views::transform, their default constructor is redefined as:
template>…
In [range.iota.view], the well-known constructor of iota_view is defined as follows (emphasis mine):
constexpr explicit iota_view(W value);
Preconditions: Bound denotes unreachable_sentinel_t or Bound() is
reachable from value.
Effects:…
Inspired by cute cppreference example of trim with C++20 I have written the following code(I have changed the return type to void and arg to std::string& since my "problem"(I am inventing problems to learn C++20) does not exist in original code that…
Consider the following code:
#include
int main() {
constexpr int a[] = {1, 2, 3, 4};
constexpr auto r = a | std::views::take(3);
static_assert(*r.begin() == 1);
}
msvc accept it, gcc rejects it with:
:5:44: error:…
I studied the weakly_incrementable concept recently and I am wondering what the post-increment operator is good for, given that the concept does not define any requirements for the result of the operation.
Is it actually okay to return void for…
Consider the following code:
#include
#include
constexpr inline auto filter_upper = std::views::filter(::isupper);
The new range adaptors filter_upper works fine with global old c-function ::isupper, but if I replace with…
I want to convert four bytes contained in a span into a string using ranges. Here's an example of input and output:
std::span data{bytes}; // contains 0x11, 0x22, 0x33, 0x44
std::string result = ...; // results in 44:33:22:11
Here's…
This function f can take C++20 ranges algorithm objects as an argument then use it:
constexpr auto f(auto algo) {
return [=] {
algo(std::array{1, 0});
return true;
}();
}
and it works fine with…
I'm getting this error on macOS, with clang, using std=c++20 or std=c++2b .
error: no member named 'split' in namespace 'std::ranges::views'
auto tokensRanges = blob | std::views::split('.');
Compiler details:
Apple clang version 14.0.3…
I am learning about ranges and as I learned about range adaptors, they only accept viewable_range as the first argument according to cppreference RangeAdaptorObject.
But when I tested this code on Compiler Explorer:
auto val =…