Questions tagged [std-ranges]

A library for C++20 that introduced std::ranges namespace, which consists of rangified algorithms from header and of range adaptors divided into views and actions.

379 questions
0
votes
1 answer

Does std::reverse_iterator work with adapted ranges?

I remember having read that the motivation for [forward.iterators]/6 (requiring that, given two iterators a and b, a == b if and only if *a and *b are bound to the same object) was to support reverse_iterators. Am I remembering…
metalfox
  • 6,301
  • 1
  • 21
  • 43
0
votes
1 answer

C++20 ranges - how to modify a range?

I have a vector defined as: auto xs = std::vector(5) = { 1.0, 2.0, 3.0, 4.0, 5.0 }; and I've created a view on this vector: auto vi = xs | std::ranges::views::drop(1); for example. However, I'd like to convert the view data into an…
Andrew
  • 626
  • 6
  • 16
0
votes
1 answer

How to define a type for a ranges::view without defining it initially?

I need to specify different ranges::view's depending upon a variable. Such as: #include #include auto main() -> int { std::vector xs = { 1.0, 2.0, 3.0, 4.0, 5.0 }; auto x = int(0); auto vi; if(x == 0) …
Andrew
  • 626
  • 6
  • 16
0
votes
1 answer

Make iterator work with std::ranges functions

I have the following code for a 2D-grid iterator. #include using std::ranges::count_if; using std::ranges::for_each; #include using std::endl; using std::cout; #include using std::iterator; using…
Richard Neumann
  • 2,986
  • 2
  • 25
  • 50
0
votes
0 answers

Why does the Microsoft implementation of concept std::output_iterator contain a cast of type T?

Ranges are complete in VS2019, see https://devblogs.microsoft.com/cppblog/c20-ranges-are-complete-in-visual-studio-2019-version-16-10/ Why does the output_iterator concept have a static cast in the definition below taken from the Microsoft…
René Hiemstra
  • 117
  • 1
  • 4
0
votes
1 answer

C++20 ranges reverse view problem in VS2019 (latest)

I'm trying to read a vector in the reverse order using a ranges::subrange view but I'm confused about how it should work. I'm aware of ranges::reverse but I'm trying to avoid using this method as a personal preference and learning experience. My…
Andrew
  • 626
  • 6
  • 16
0
votes
0 answers

Filter vector with std::ranges

I'd like to get from a vector of collected Data (each has a time stamp) only the elements which are newer than a specified time. savedPublishedData is a map where i look for the id. savedPublishedData.second is thn a vector of Data (Custom Class),…
Mitch
  • 27
  • 5
0
votes
1 answer

std::regular_invocable and by value arguments

Is it intended that following example exhibit precondition violation? #include #include #include #include int main() { std::vector x{1, 2, 3, 4}; auto r = x | std::views::transform([](int…
Serikov
  • 1,159
  • 8
  • 15
0
votes
1 answer

How to print a range?

I'm trying to compare 2 arrays using ranges and want to print this. #include #include #include #include #include int main() { std::array test{0, 2, 3, 8, 0, 5, 4, 0, 1}; std::array
kramer
  • 177
  • 1
  • 4
  • 15
0
votes
1 answer

Unable to Satisfy Constraint for ranges::count()

I'm exploring the ranges functions. struct User { std::string name; int age; std::string gender; template friend Os& operator<<(Os& os, User const& u) { return os << "\n" << std::right << std::setw(10) …
SimpleCoder
  • 45
  • 1
  • 8
0
votes
2 answers

c++20 Sorting Vector of structs with structs member variable and std::ranges

I have a simple struct struct MyStruct { int x; } I have a vector of MyStructs. vector myStructs; int n = 10; for(auto i = 0; i < n; i++) myStructs.push_back(MyStruct{.x = n - i}); How will I sort myStructs according to member…
Inyoung Kim 김인영
  • 1,434
  • 1
  • 17
  • 38
0
votes
2 answers

Is there any possible way to get origin value using transformed iterator?

C++20 introduces the views::elements, views::keys and views::values to easily deal with range of tuple-like values: std::vector v{std::tuple{'A', 1}, {'B', 2}, {'C', 3}}; auto it = std::ranges::find(v | std::views::elements<0>, 'B'); assert(*it ==…
康桓瑋
  • 33,481
  • 5
  • 40
  • 90
0
votes
0 answers

Cannot assign ranges transform to vector after updating to VS2019 16.6

I was on an earlier version of VS2019 (16.2 I believe) and upgraded to 16.6 yesterday and suddenly working code is throwing compiler errors and I can't figure out how to clear them up. I have the following code: std::vector run( const…
Mordred
  • 3,734
  • 3
  • 36
  • 55
0
votes
1 answer

Why doesn't libstdc++ have span::span(Container&)?

According to cppreference, in C++20, std::span is supposed to be constructible using container references: template constexpr span(Container& cont); template constexpr span(const Container& cont); but in the…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
-1
votes
1 answer

Concept and ranges

I'd like to define a concepts that is true if t.ok(c) compiles and returns a bool, where t is a template parameter of type T and c is a "concrete" type of type C t.around(c) compiles and returns something that can be iterated over (the type of each…
R. Absil
  • 173
  • 6
1 2 3
25
26