I am trying to use the Ranges-V3 library to slice a container of values ββinto a range of ranges, so that neighboring ranges share boundary elements.
Consider the following:
using namespace ranges; std::vector<int> v = { 1, 2, 3, 0, 4, 0, 5, 0, 6, 7, 8, 0, 0, 9 }; auto myRanges = v | for_each( myRanges, []( auto&& range ){ std::cout << range << std::endl;} );
I would like to divide the range into overlapping subranges based on whether the region fills two criteria:
- does the element have a value of zero
- or adjacent to one or more elements with a value of zero
Required Conclusion:
[1,2,3] [3,0,4,0,5,0,6] [6,7,8] [8,0,0,9]
my attempt:
auto degenerate = []( auto&& arg ){ return distance( arg ) < 2; }; auto myRanges = v | view::split(0) | view::remove_if( degenerate ); for_each( myRanges, []( auto&& range ){ std::cout << range << std::endl;} );
Output:
[1,2,3] [6,7,8]
I do not understand how I can
- insert range from 3 to 6
- add range from 8 to 9