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
3
votes
2 answers

Generating a ranges::view from a raw pointer (decayed C style array) and a size

Using a function from a C library providing a pointer and a size, is there (or will there be) a way to generate a ranges::view directly from it ? As I understood, views need a begin iterator and a sentinel, so will I have to copy the content of the…
yannick
  • 95
  • 6
3
votes
1 answer

Transform using range-v3

I am trying below code using ranges but it doesn't working. // Code std::map m{ {1,"foo"},{42,"bar"},{7,"baz"} }; std::vector keys; // without using ranges std::transform(begin(m), end(m), std::back_inserter(keys), [](auto…
3
votes
1 answer

How to chain ranges::view conditionally?

Simply put, how do I programnatically branch on a view chain construct? Because now what I can think of is just #if, in which is not a very good idea. auto adaptor = view::drop(x0) #if branch1 | view::drop(x1) #elif branch2 |…
sandthorn
  • 2,770
  • 1
  • 15
  • 59
3
votes
1 answer

Why is std::back_inserter_iterator not WeaklyIncrementable in RangeV3?

To my surprise this Concept-like assertion fails in RangeV3. #include #include int main(){ static_assert(ranges::WeaklyIncrementable >>()); } Why is that? This,…
alfC
  • 14,261
  • 4
  • 67
  • 118
3
votes
0 answers

Structured-binding declaration of a range in range-v3

The c++2a working draft has the std::ranges::subrange utility, which enables ranges and views to be unpacked into an iterator and a sentinel; for example: std::optional foo(std::vector const &v, std::size_t const n) { auto [it, e] =…
metalfox
  • 6,301
  • 1
  • 21
  • 43
3
votes
1 answer

C++20 range-v3 and the zip_with view adapter

With a lazy range combinator such as ranges::view::reverse I can either provide it with a single argument (e.g. reverse(iota(0,3))); or I can use it to adapt a range using operator| (e.g. iota(0,3) | reverse). This parity appears fairly regular;…
user2023370
  • 10,488
  • 6
  • 50
  • 83
3
votes
1 answer

range-v3: Joining piped ranges with a delimeter

I'm trying to build a basic demo of the range-v3 library: take some integers, filter out odd values, stringify them, then join those into a comma-separated list. For example, { 8, 6, 7, 5, 3, 0, 9 } becomes "8, 6, 0". From reading the docs and going…
Matt Kline
  • 10,149
  • 7
  • 50
  • 87
3
votes
2 answers

Unpacking a range of tuples into n-ary function

Suppose I have a range of tuples e.g. coming from the zip function. Do the functions which operate on that range have to be always unary or does there exist some transformation which unpacks the tuple into the function's arguments. Basically, I'd…
kyku
  • 5,892
  • 4
  • 43
  • 51
3
votes
3 answers

Multiple iterators to a complex range

I am trying to have multiple iterators to a bit more complex range (using range-v3 library) -- manually implementing a cartesian product, using filter, for_each and yield. However, when I tried to hold multiple iterators to such range, they share a…
CygnusX1
  • 20,968
  • 5
  • 65
  • 109
3
votes
1 answer

Why is the interleave_view missing in the range-v3 library?

In Eric Niebler's range-v3 calendar example he uses interleave followed by chunk to transpose a matrix. I wonder why interleave is not part of the range-v3 library...
Porsche9II
  • 629
  • 5
  • 17
3
votes
3 answers

Sort by non-lazy lambda expression / projection

I have an array of element of some type T. For some complex function I would like to sort the array by the value of that function. Efficiently. When I did some research on how to do such a thing, I quickly found that range::v3::sort, from the…
CygnusX1
  • 20,968
  • 5
  • 65
  • 109
3
votes
1 answer

Explicit range-v3 decltype evaluates to void?

I am trying to get an explicit type of a range (I may want to store it as a field in a class in the future). However, for some reason, it evaluates to void? #include #include #include class Alpha…
CygnusX1
  • 20,968
  • 5
  • 65
  • 109
3
votes
1 answer

How to output C++ range-v3 to ostringstream?

This range-v3 example doesn't compile with Visual C++ version 15.9: auto letters = ranges::view::iota('a','g'); std::ostringstream out; out << letters; Is this by design? What is the way to output ranges to ostringstream?
Paul Jurczak
  • 7,008
  • 3
  • 47
  • 72
3
votes
1 answer

ranges-v3 / sort confusion

I'm a bit simple it seems as I'm not quite able to see clearly the cause of this error on the line marked error below. std::sort and boost::sort picks up the default predicate, but ranges-v3 doesn't for some reason. This is ranges-v3 0.36. Similar…
Matt Hurd
  • 125
  • 7
3
votes
0 answers

Why does adding a view::filter trigger multiple redundant sentinel checks?

Given str is a string auto str = std::string{}; getline(std::cin, str); I notice when we have a view::filter exist on a lazy range, there will be many redundant sentinel checks even with -O3. CE godbolt.org/g/B3ZGbm for (auto sv : str |…
sandthorn
  • 2,770
  • 1
  • 15
  • 59