Questions tagged [range-v3]

range-v3 is a range library for C++14/17/20.

range-v3 is a range library for C++14/17/20. It is the basis of a formal proposal (N4128 Ranges for the Standard Library) to add range support to the C++ standard library. It also is the reference implementation for a Technical Specification (N4560 Working Draft, C++ extensions for Ranges). Source is available on Github.

313 questions
6
votes
1 answer

CONCEPT_REQUIRES_ implementation in ranges-v3

Trying to learn how to use Eric Niebler's ranges-v3 library, and reading the source code, I saw that macro definition: #define CONCEPT_PP_CAT_(X, Y) X ## Y #define CONCEPT_PP_CAT(X, Y) CONCEPT_PP_CAT_(X, Y) /// \addtogroup group-concepts …
ABu
  • 10,423
  • 6
  • 52
  • 103
6
votes
1 answer

Why are there const overloads of mutating Boost.Range algorithms?

The documentation (and the implementation) of Boost.Range shows overloads of the mutating algorithms that take const refs as arguments. For instance Boost.Range's Sort documentation shows: template RandomAccessRange&…
akim
  • 8,255
  • 3
  • 44
  • 60
6
votes
2 answers

why does range-v3 yield require default constructor

I am trying to understand, for what reasons does the yield family of functions require that class be default constructible? In the following example, the vnums1 line compiles only if CNum has a default constructor. The vnums2 line does not require a…
6
votes
2 answers

How to properly forward Invocable types

I really like to use cmcstl2, an implementation of the Ranges TS. I especially like the optional projections on every STL-algorithm. Invocable types get forwarded (ehm... or not) like this: (min_element.hpp) template
Maikel
  • 1,204
  • 7
  • 19
6
votes
1 answer

How do I transform a vector into a new vector using range-v3?

I am coming from the C# world where I can write something like: var newList = oldList.Select(x => x * 2).Where(x => x > 3).ToList(); This allows me to take a list, transform it in some way, and store the result in a new list. I would like to do…
sdgfsdh
  • 33,689
  • 26
  • 132
  • 245
5
votes
1 answer

Why does C++23 ranges::to not constrain the container type C to be a range?

C++23 introduced the very powerful ranges::to for constructing an object (usually a container) from a range, with the following definition ([range.utility.conv.to]): template requires (!view) constexpr C…
康桓瑋
  • 33,481
  • 5
  • 40
  • 90
5
votes
1 answer

Range-v3: Why is ranges::to_vector needed here?

I'm trying to compute a reversed views::partial_sum. The code below gives the expected result of a non-reversed partial_'min', but I need to use ranges::to_vector in order to un-views::reverse the final result (since you can't views::reverse a…
Tom Huntington
  • 2,260
  • 10
  • 20
5
votes
0 answers

Under what circumstances does the iterator of ranges::split_view not satisfy copyable?

C++20 introduces a ranges::split_view, which accepts a view and a delimiter, and splits the view into subranges according to the delimiter. The delimiter is also a view, and when it is a single element, it will be wrapped in a…
康桓瑋
  • 33,481
  • 5
  • 40
  • 90
5
votes
1 answer

Range-v3 view composition and views calculation parallelization

Taken from range-v3 docs, the following example demonstrates a simple composition of views pipelined to produce a range: std::vector const vi{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; using namespace ranges; auto rng = vi | views::remove_if([](int…
gonidelis
  • 885
  • 10
  • 32
5
votes
1 answer

Why does ranges::sort return an iterator?

I can see that std::sort returns void. But now that ranges have been added to the C++20 Standard, why does std::ranges::sort return an iterator? cppreference specifies: Return value An iterator equal to last. What's the rational behind that…
gonidelis
  • 885
  • 10
  • 32
5
votes
3 answers

How to convert a pair of iterator into a view?

I have a pair of iterator, and I would like to use ranges::views::filter(some_predicate) on it (with the pipe operator). AFAIU I should first convert my pair of iterator into a view. I tried to use ranges::subrange(first, last) to do so, but I’m…
Robin
  • 423
  • 3
  • 10
5
votes
1 answer

How to project std::tuple in c++20 constrained algorithms

Suppose we have a array of std::pairs: using Particle = std::pair; Particle particles[] {{"Electron", 0.511}, {"Muon", 105.66}, {"Tau", 1776.86}}; We can using C++20 ranges algorithms with different projection function to sort…
康桓瑋
  • 33,481
  • 5
  • 40
  • 90
5
votes
1 answer

std::ranges::elements_view for custom tuple-like data

I have an use case that can be reduced to: #include #include #include struct TDat { double x, y; template friend double &get(TDat &Dat) { if constexpr (I == 0) return Dat.x; else return Dat.y;…
metalfox
  • 6,301
  • 1
  • 21
  • 43
5
votes
1 answer

how to combine ranges v3 transform, join and cycle?

I'm trying to generate an infinite range of integers using range-v3 library. My goal is to have {0,0,0,1,1,1,2,2,2,0,0,0,1,1,1 ...}. I would like the number of times each number is repeated to be variable also. without this limitation, I can do…
jslap
  • 711
  • 1
  • 6
  • 21
5
votes
1 answer

How do I check if ranges:: algorithms like find_if returned a value?

For example, if I want to find the smallest element of a collection, but only the smallest even element, I'd like to call ranges::min_element with a filtered range like so: using ranges::views::filter; using ranges::min_element; std::vector
AndyG
  • 39,700
  • 8
  • 109
  • 143