I’m new to range-v3. I started by write a program that generates a range of integers, modifies it, and prints out the resulting range. I used a modifier from the actions
library, which rendered my code non-iterable.
Could someone help me understand how to convert a ranges::action::action_closure
into an iterable?
Here’s the example I started with – a function that generates and prints out a range of numbers. This code works fine and compiles.
void generate_and_print_numbers_using_streams_and_iterators() {
auto v = views::iota(1, 5); // <-- this code works fine with streams and iterators.
// this works
cout << v << endl;
//this works too
for (auto s: v) {
cout << s << ", ";
}
cout << endl;
// and this works too
for (auto it = v.begin(); it != v.end(); ++it) {
cout << *it << ", ";
}
cout << endl;
}
Then I tried introducing the action I mentioned. This code no longer compiles – v
is no longer a view, but an action_closure
which does not define begin()
and end()
functions.
void generate_and_print_numbers_using_streams_and_iterators() {
// I REPLACED THIS:
// auto v = views::iota(1, 5);
// WITH THIS:
auto v = action::push_back(views::iota(1, 5)) | actions::unique; // Wrapped iota in push_back
// .. the remainder of the function is unchanged
I tried searching through the documentation of ranges-v3, as well as googling this conversion. The only thing I found was the following article that shows how to convert a view to a concrete container (a vector).
I will appreciate any help on this topic.
You may also like…
- Merge Sorted Array without Extra Space
- Update Spring Embedded Entity throws Stack Overflow Entity
- How to use artifactory query language inside a jenkins pipeline instead of having it call from a file
- Is there a reliable alarm clock? Alarm Manager?
- Obj-c – Remove string from key in multiple dictionaries in array?
- should i use for loop or while loop to make a break timer in python?
- Get insights and post data from Facebook API
- how to display url taxonomy in loop taxonomy wordpress?
- Typescript determine nested object type from Union Type
- Flutter audioplayers seek when dragging not working on iOS Lock Screen
- Format output into an HTML file
- Assign color to value (reupload)
- Is there a way to resolve OptimisticLockingFailureException in Spring Batch?
- How to build a thread safe in-memory cache per request scope with Spring Boot
- Cannot Archive in Xcode
- std: bad_alloc runtime error in javascript code
amazon-web-services android angular api arrays c# css dart dataframe django docker excel express firebase flutter html ios java javascript jquery json kotlin laravel linux list mongodb mysql node.js pandas php postgresql python python-3.x r react-native reactjs regex spring spring-boot sql sql-server string swift typescript vue.js