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
1
vote
1 answer

What is the most idiomatic way of creating a range of indices from a container?

Is there a better way of iterating over the indices of a container than doing something like this for (auto i : view::iota(0, vec.size()) Ideally something that would look just like this view::something(vec). I understand I can write my own…
user975989
  • 2,578
  • 1
  • 20
  • 38
1
vote
1 answer

Emulate a python-style list comprehension in c++ using rangesv3?

Using the rangev3 library I can do this: auto march = view::iota(1,32) | view::transform( [](int i){return date(1995, greg::Mar, i); }); giving me the dates in the march of…
1
vote
1 answer

range-v3 how to action::join with delimiter

I get range-v3 for MSVC from git. And compile by MSVC C++14 compiler. Consider code: auto getter2 = [](const std::string&r) { return r+r; }; std::vector vv = { "11","22", "33" }; std::cout << (vv | view::transform(getter2) |…
Alexey Subbota
  • 938
  • 6
  • 23
1
vote
1 answer

Range-V3: get base iterator

I try to use Range-V3 library (for MSVC), but due to lack of documentation I don't understand how to do one thing. std::map ss = { {1,L"1"}, {2,L"2"}, {3,L"3"} }; auto rng = ss | ranges::view::reverse | ranges::view::values; auto…
Alexey Subbota
  • 938
  • 6
  • 23
1
vote
1 answer

How to determine equivalence between `ranges::view` object and `std::vector`?

I'm using the excellent range-v3 library. One of my functions returns a ranges::view object which I'd like to compare to a std::vector. Of course, I can compare element-by-element, but there's got to be a better way. How to determine equivalence…
jlconlin
  • 14,206
  • 22
  • 72
  • 105
1
vote
2 answers

C++ Ranges TS include experimental path

I am looking to use C++ Ranges. Working Draft, C++ Extensions for Ranges says: The Ranges library provides the Ranges library headers, shown in Table 2. Table 2 — Ranges TS library headers
CW Holeman II
  • 4,661
  • 7
  • 41
  • 72
1
vote
2 answers

Invoking ranges::for_each with lambda and global function

The following code works as expected: void foo(auto const &){} auto const rng{ranges::view::all(v)}; ranges::for_each(rng, [](auto const & r){ foo(r); }); But the following: void foo(auto const &){} auto const…
nikitablack
  • 4,359
  • 2
  • 35
  • 68
1
vote
1 answer

v3 make_iterator_range requirements

I am trying to convert my range (pair of iterators) to iterator_range so that I can take advantage of all the views and actions. I am able to convert my range to boost::iterator_range, but am getting a compilation failure when converting to…
skgbanga
  • 2,477
  • 2
  • 20
  • 29
1
vote
1 answer

Range v3. Difference between two ranges

I am trying to get the difference between two ranges but have little luck. Something like vector l{ 1,5,6 }; auto diff = views::ints(1,10) - view::all( l ); ==> Range { 2,3,4,7,8,9 } By the way. Are there any good writings on range-v3?…
Generic Name
  • 1,083
  • 1
  • 12
  • 19
1
vote
0 answers

RangeV3: why not specialize algorithm for specific containers?

The "old" STL does not allow say std::find to be specialized to use the member functions for std::set or std::unordered_map, etc. It cannot, since the former use iterators, the latter need the containers, and from iterators there are no means to…
akim
  • 8,255
  • 3
  • 44
  • 60
0
votes
1 answer

How does ranges::any_view work and how is it behaving in conjunction to cache1 in these cases?

tl;dr It's not clear to me how ranges::any_view works, especially in relation to what T is, i.e. a &, a const&, a value type, or what else.¹ Research There isn't really much about it here, yet, nor I have found much around, beside this very…
Enlico
  • 23,259
  • 6
  • 48
  • 102
0
votes
0 answers

Is ranges::actions::sort just a wrapper to ranges::sort? If not, what's the difference?

From the code it seems like ranges::actions::sort has one overload that indeed forwards all arguments to ranges::sort, and another one which… well, I've got a bit lost into the rabbit hole of bind_back and make_action_closure, but the point is that…
Enlico
  • 23,259
  • 6
  • 48
  • 102
0
votes
0 answers

Iterate on several vectors one after another?

I have a vector of vectors: std::vector>. I would like to know, is there any utility in range-v3 or std::ranges to iterate consecutively on the internal vectors? I know there is ranges::views::concat, but apparently I have to list…
jjcasmar
  • 1,387
  • 1
  • 18
  • 30
0
votes
1 answer

converting a flat table to a tree structure using ranges-v3

I have a flat representation of a tree shown in the table below. The unsorted data, std::vector is: unsorted vector (id) (path) (fn) (line) (extra) 1 /abc/file3.c foo0 10 1 2 /abc/file3.c foo0 15 2 3…
johnco3
  • 2,401
  • 4
  • 35
  • 67
0
votes
1 answer

Create a custom transformable view in ranges-v3

I want to create my own view using the ranges-v3 library. One should be able to pipe this view into ranges::views::transform(...) without problem, alas my current approach does not seem to allow this. The scenario: I have made a function that does…
Michael A
  • 151
  • 1
  • 7