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
0
votes
0 answers

How to wrap some computed values in a range in order to allow using join on the output of transform?

The original question I have a piece of code where I process a std::vector by splitting it into groups and processing each group. An if-else determines the processing each group undergoes: groups taking the if branch will end up giving a single…
Enlico
  • 23,259
  • 6
  • 48
  • 102
0
votes
1 answer

What is the correct way to "wrap" an object in the appropriate monad/applicative with Range-v3?

Let's say that given a range like this std::vector v{1, 4, 7, 2}; I want to generate another range where all even numbers are repeated a number of times equal to their value, whereas all odd numbers are left unchanged. A possible solution is…
Enlico
  • 23,259
  • 6
  • 48
  • 102
0
votes
1 answer

Does a range convert to bool via emtpy() member function when used as a if condition?

The following code compiles, runs, and gives the result as if range is being converted to bool via range.empty(). Is it actually what happens? I'm really not comfortable enough in navigating Range-v3 headers, so I'm asking this question…
Enlico
  • 23,259
  • 6
  • 48
  • 102
0
votes
2 answers

ranges::views::group_by-like function applying predicate to consecutive elements?

In the following small example I was trying to group elements by the difference between consecutive elements being 1. As the output shows, however, group_by's predicate is evaluated between the current element and the first element of the group…
Enlico
  • 23,259
  • 6
  • 48
  • 102
0
votes
3 answers

Month of day with sequence in one for loop or range-v3 lib

I try to take month of day with sequence like this: for january it will print 1 with 31 time, in february will print 2 with 28 time etc. std::vector list = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int count = 0; for(int k = 0; k < 12;…
darkboy
  • 35
  • 6
0
votes
1 answer

split a range of numbers into several ranges with ranges-v3

I have a certain amount of points and some tetrahedra in space and, for each point, I compute in which tetrahedron it is. Point that are not in a tetrahedron are discarded. auto samplerIdAndCoarseTetra = mcSamplers …
jjcasmar
  • 1,387
  • 1
  • 18
  • 30
0
votes
0 answers

Apply algorithm on projection but retrieve information from original container

I would like to apply an algorithm on a projection of a container, but then use that information to retrieve information from the original container. In the contrived example below, I would like to use iter to find the related key-value pair in…
singhh23
  • 97
  • 7
0
votes
0 answers

What is the type signature of a range from the range-v3 library in C

Given the code below: // This example demonstrates filtering and transforming a range on the // fly with view adaptors. #include #include #include #include #include…
Brian Yeh
  • 3,119
  • 3
  • 26
  • 40
0
votes
0 answers

Why does GCC's stdlibc++ define WeaklyIncrementable iterator requires moveable and it's difference_type must be integral? What benefits do they give?

While I'm trying to understand the ostream_joiner's std::ranges algorithm requirement concept failure fiasco, I found that GCC implementation of WeaklyIncrementable iterator looks somewhat different from the standard. GCC 10.2 stdlibc++…
sandthorn
  • 2,770
  • 1
  • 15
  • 59
0
votes
1 answer

array to vector range v3 style on VS2019

I want to convert an array to a vector so that I can do a ranges::views::concat on two vectors of the same type but I'm having difficulty doing this. I have the following code: #include #include static…
Andrew
  • 626
  • 6
  • 16
0
votes
0 answers

Best way to join string with transform in a standard way

I'm looking for the best way to join a container with transformation as a string. The old style, that I'm using looks like this: std::string MyJoin(const std::vector& foos) { std::string str; for (size_t i = 0; i < foos.size(); ++i) { …
Jake Jung
  • 1
  • 1
0
votes
0 answers

Why you can't use pointer to member as a callable / invokeable in range-v3 for_each?

Suppose I have a bar and a foo structures: struct bar { void bar_function() { } }; struct foo { bar* bar_ptr; void foo_function() { } }; Now, I'd like to call bar_function() on each of foo's bar_ptrs from an std::vector of…
Fureeish
  • 12,533
  • 4
  • 32
  • 62
0
votes
1 answer

Updating results during runtime with Ranges

Using Range library for C++14/17/20 extension I noticed that when i store some results of range::views::method() operations that, during runtime, every change or update of the original data will cause the same changes to it's new constructed…
rekkalmd
  • 171
  • 1
  • 12
0
votes
1 answer

how do to declare a range::v3::View variable from an unknown view

I have almost the same question as a previous post: "How do you declare a ranges-v3 view return value?" But that answer simply said to avoid declaring a return type and use auto instead, which doesn't solve my problem, and I can't find this…
0
votes
1 answer

The range library implementation of the copy algorithm

I am building some snippets that should work with both the C++20 Ranges library and the range-v3 library and I noticed some differences in the implementation of the copy algorithm. The following code using C++20 ranges library (from the Standard…
Marius Bancila
  • 16,053
  • 9
  • 49
  • 91