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

overload resolution from magic number to int or long (in range-v3)

In range-v3, view_facade class has begin() function. template())> detail::facade_iterator_t begin() { return {range_access::begin_cursor(derived(), 42)}; } And the…
RammerChoi
  • 99
  • 6
4
votes
1 answer

How to create a custom container for range-v3

I understood how to create my own range-v3 views using view-facade, but now I would like to create my own container so I can use in-place-mutating actions: MyContainer list = createList(); list |=…
Anselm Eickhoff
  • 589
  • 2
  • 5
  • 14
4
votes
1 answer

Could range-based algorithm be fully independent of (and yet optimized for any) container type?

I was wondering if boost::range or range_v3 will reconciliate free functions and member functions in a similar way that std::begin reconciliates STL containers and C-like arrays (in terms of coding genericity I mean)? More particularly it would be…
4
votes
1 answer

Is there and neat equivalent to view a member function/variable?

Streams library has a neat map function to view a range by a member function. Is there any equivalent view in Range-V3? Would view::transform be the only option?
Viktor Sehr
  • 12,825
  • 5
  • 58
  • 90
3
votes
2 answers

how to split a string into sequences defined by a rule with range v3 library?

I have a string of vehicle number, for example kz083y68 and i want to convert it into kz 083 y 68 with spaces. String also could be 3486nv09, etc, so there is no fixed position to split. All i need is to split subsequences of numbers and letters by…
3
votes
1 answer

In range-v3, can not create a subrange from two iterators

Problem I want to create a range from two iterators returned by a function. I used the answer to a related question to create a new subrange using range-v3: auto [it1, it2] = out_edges(u, _graph); return ranges::subrange(it1, it2) |…
WaterFox
  • 850
  • 6
  • 18
3
votes
1 answer

ranges::views::filter no longer compatible with std::optional, msvc v19.36

Edit: My confusion came from not understanding the explicit specifier and contextual conversions to bool In v19.35 you could pass an invocable to ranges::views::filter that returned std::optional. In v19.36 you…
Tom Huntington
  • 2,260
  • 10
  • 20
3
votes
1 answer

Why does the random access property of iota_view depend on the element type? And how to write a Foo such that iota(Foo{1}, Foo{10}) is random-access?

The following code fails to compile if you uncomment the commented line. (Compiler Explorer) Why is that? I imagine the reason is that the iota_view of Foos doesn't know how to advance a Foo. But how do I make it know? #include #include…
Enlico
  • 23,259
  • 6
  • 48
  • 102
3
votes
1 answer

In C++ and range-v3, how to first transform a view and then convert it to a map?

Having any range as an input, how to first convert its elements to tuples and then save them in a std::map with ranges::to? This code works and creates a vector of tuples: #include #include #include…
notsurewhattodo
  • 446
  • 4
  • 11
3
votes
1 answer

What does ranges::starts_with do with C-style string argument(s)?

The following code prints 1010 #include #include int main () { using namespace std::literals; std::cout << ranges::starts_with("hello world"s, "hello"s) <<…
Enlico
  • 23,259
  • 6
  • 48
  • 102
3
votes
1 answer

Possible ways to make this `cartesian_product_with_filter` function variadic?

I am trying to implement a function that calculates the Cartesian product of ranges. I know there's views::zip and views::cartesian_product available, and am just deepening my understanding of the use of the range library by writing this function…
FeignClaims
  • 193
  • 8
3
votes
1 answer

How to declare a function, that takes a range

I want to declare a function, that gets a range as input, outputs a single number and use it directly with ranges::views::transform of the range-v3 library. The following works but I have to use a lambda that doesn't really do anything. int64_t…
Grimkin
  • 107
  • 5
3
votes
0 answers

When to use specifically the niebloid std::ranges::construct_at instead of std::construct_at?

In the situation that we have two choices of exactly the same functionality. One is a niebloid, the other is a function. Are there any guidelines for this in general? std::construct_at -…
sandthorn
  • 2,770
  • 1
  • 15
  • 59
3
votes
1 answer

How do you make a pipeable function like ranges::to() with range-v3 ranges?

My general question is how do you make something like ranges::to() for classes for which ranges::to() does not work? But specifically I am looking for a pipeable way to construct a boost geometry multi_linestring from a range-v3 range view of…
jwezorek
  • 8,592
  • 1
  • 29
  • 46
3
votes
2 answers

how to use a vector of keys to filter values from a map and produce a set using c++ ranges syntax

I am new to Eric Niebler's ranges-v3 library and I would like to solve the following simple problem: I have a std::map containing the following: std::map map = { {"THIS", 1}, {"IS", 2}, {"A", 3}, {"TEST", 4}, {"WITH", 5},…
johnco3
  • 2,401
  • 4
  • 35
  • 67