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.
C++20 brings a more powerful iterator system, one of them is to introduce iterator_concept on the basis of iterator_category.
I found that the iterator_concept and iterator_category of many iterators in C++20 are inconsistent. Take the most famous…
I'm dealing with the last big 4 of C++ 20, attempting to learn the new main features.
Trying some code from the web related to ranges, I've written:
std::vector ints{ 6, 5, 2, 8 };
auto even = [](int i) {
return 0 == i % 2;
};
// ranges...
auto…
See: http://eel.is/c++draft/#ranges
Given two C++2a ranges (as in objects that conform to the ranges concept of the ranges library) a and b, of equal length, is there a way to zip them together such that:
for (const auto& [a,b] : zip(a,b))
does…
C++20 (and 23 with std::ranges::to()) makes idiomatic the use of operator| to make a pipeline of transformations such as this:
return numbers
| std::views::filter([](int n) { return n % 2 == 0; })
|…
Why does this code work with the #if 0 block in place, but fails with a fairly complex set of error messages if you remove it? And more importantly, how do I make it the same result as the very similar block above it?
#include
#include…
On cppreference on std::ranges::less, in notes we can see that:
Unlike std::less, std::ranges::less requires all six comparison operators <, <=, >, >=, == and != to be valid (via the totally_ordered_with constraint).
But... why? Why would we use…
I noticed that std::ranges::sort cannot sort std::vector:
:6:51: error: no match for call to '(const std::ranges::__sort_fn) (std::vector >)'
6 | std::ranges::sort(std::vector{false, true, true});
| …
I was writing a simple C++ program that generates a list of random integer values from a normal distribution, then takes first N generated items and filters them so that their absolute value is greater than 42. The code i wrote is the following:
int…
I have a piece of code that uses the ranges library of C++20, taken from this SO anwer. The code is rejected by some compiler (versions) and some older GCC versions return garbage. Which compiler is right?
The code is supposed to print the elements…
Say I have a custom container class that stores data in a map:
class Container
{
public:
void add(int key, std::string value) { _data.emplace(key, std::move(value)); }
private:
std::map _data;
};
I want to provide an…
C++20 introduced a std::common_iterator that is capable of representing a non-common range of elements (where the types of the iterator and sentinel differ) as a common range (where they are the same), its synopsis defines…
I wanted to create a deep_flatten function template that would produce a range of elements that are deeply joined. For example, if we take into account only nested std::vectors, I can have:
template
struct is_vector : public…
Some ranges adaptors such as filter_view, take_while_view and transform_view use std::optional's cousin copyable-box to store the callable object:
template
class transform_view : public…
I have a simple container:
template >
class ring
{
public:
using value_type = T;
using allocator_type = Allocator;
using size_type = std::size_t;
using difference_type = std::ptrdiff_t;
…
The main purpose of this question is to draw community's attention to libstdc++ ranges not working with clang: https://bugs.llvm.org/show_bug.cgi?id=46746
Avi Kivity suggested this is a gcc bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97120
But…