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
4
votes
1 answer

How to emulate Haskell's Data.List.transpose in C++ with Range-v3?

These are some inputs and relative desired outputs std::vector v1{"aeiou", "bcdfghjk"}; std::vector v2{"aeiou", "bcd"}; auto w1 = v1 | wanne_be_transpose; auto w2 = v2 | wanne_be_transpose; // w1 =…
Enlico
  • 23,259
  • 6
  • 48
  • 102
4
votes
1 answer

How to project elements nestedly in c++20 constrained algorithms?

Suppose I have a std::vector of std::pairs, then I can using c++20 constrained algorithm's projection facility to sort elements according to sub-object: std::vector> v; // sort by std::string ranges::sort(v, {},…
康桓瑋
  • 33,481
  • 5
  • 40
  • 90
4
votes
1 answer

Create a view by selecting elements of a range by their index

In range-v3, is there a more efficient way (less steps, cleaner, more expressive, more elegant, more performant, ...) to create a view by selecting elements of a range by arbitrary indexes of the range than using views::counted plus views::concat as…
yannick
  • 95
  • 6
4
votes
1 answer

C++ Ranges-v3 with std::span: ownership of intermediate objects when returning range views from functions

I'm a complete beginner with Eric Niebler's ranges-V3 library (which I love so far!), but have been fighting with some problems when returning ranges from from functions. I think I found the problem, but am a bit surprised by the default behavior…
ulf
  • 190
  • 1
  • 6
4
votes
2 answers

Why is a simple iterator not readable?

This code does not compile with range-v3 0.10.0 (or with master). It does compile with range-v3 0.9.1. #include "range/v3/all.hpp" struct double_it { using value_type = double; double x; double& operator*() { return x; } const double&…
Bérenger
  • 2,678
  • 2
  • 21
  • 42
4
votes
2 answers

range view as data member

I'm trying out the new range-v3 library (0.5.0, clang-7.1) I'm traversing through a graph (bfs). Each node in the graph contains some vector data (std::vector). While traversing through the graph, I'm trying to create a concat_view (which is…
Surya
  • 1,139
  • 1
  • 11
  • 30
4
votes
1 answer

Is there a modifiable-view version of ranges::view::transform?

Consider the following program: #include #include #include #include #include int main() { using container = std::array, 4>; container tuples…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
4
votes
3 answers

How to fill std::array with range from range-v3?

I am a complete beginner with the range-v3 library.. Suppose I want to fill a std::array with random numbers in some interval. With iterators, I'd do something like this answer, passing iterators to my std::array in question as arguments.…
Eric Hansen
  • 1,749
  • 2
  • 19
  • 39
4
votes
2 answers

Range-v3 view::sliding(n) to return tuple (if n known at compile time)

std::vector v{1,2,3}; for (auto&& t : v | view::sliding(2)) { auto&& [first, second] = t; // error - t is a range } is there a similar view in range-v3 that can return a tuple? something like sliding<2>
Adam
  • 1,724
  • 4
  • 21
  • 31
4
votes
2 answers

make custom range v3 view pipeable

I'm trying to implement masked range views with range v3. Somehow I ended up in the situation where my implementation of ranges::view::masker(datarange, mask) works, but the piped version ranges::view::all(datarange) |…
pseyfert
  • 3,263
  • 3
  • 21
  • 47
4
votes
1 answer

Non-pointer-operand error when dereferencing an iterator into a temporary range

Using auto empty_line = [](auto& str){ return str.size() == 0; }; we can do this: auto line_range_with_first_non_empty = ranges::view::drop_while(ranges::getlines(std::cin),empty_line); auto input1 =…
sandthorn
  • 2,770
  • 1
  • 15
  • 59
4
votes
1 answer

range-v3 and view_facade, cannot model ForwardRange

This reduced test case (written following the example in the user manual) does not compile #include #include using v = std::vector; class rows : public ranges::view_facade { public: rows() = default; …
dvd
  • 1,014
  • 6
  • 12
4
votes
1 answer

C++ unexpected value type of range-v3 partial_sum view

Consider the following minimal example: #include #include namespace rng = ranges::v3; int main() { std::vector v { 6, 2, 3, 4, 5, 6 }; auto f = [](auto a, auto b) { return a*0.3 + b*0.7;}; auto…
davidhigh
  • 14,652
  • 2
  • 44
  • 75
4
votes
1 answer

How to concat two existing ranges::view?

I want to use an existing view for concatenation. In code: auto rng = view::empty>(); for(int i{0}; i < 5; ++i) { vector const & v{foo()}; // returns a reference rng |= view::concat(v); // doesn't compile - error: no viable…
nikitablack
  • 4,359
  • 2
  • 35
  • 68
4
votes
1 answer

How does range-v3's `partial_sum` not contradict non-owning reference semantics?

Consider How do I write a range pipeline that uses temporary containers?. The question is how to build a view transforming each element T using some given function std::vector f(T t); while complying with the restriction (borrowing from the top…
Ami Tavory
  • 74,578
  • 11
  • 141
  • 185