ericniebler / range-v3

Range library for C++14/17/20, basis for C++20's std::ranges
Other
4.06k stars 437 forks source link

Question about spliting a range into subranges by iterator or offset #1695

Open ashley-b opened 2 years ago

ashley-b commented 2 years ago

My question is about split, is there a way to split a range into subranges via iterators or offsets

I uses gsl::span and this helper function currently, but would like to switch to range library for this.

    template< typename T >
    std::pair< gsl::span< T >, gsl::span< T > > bisect(gsl::span< T > s, typename gsl::span< T >::index_type position)
    {
        return { s.first(position), s.subspan(position) };
    }

I see split is close to what am after, but it only works by delimiter value or predicate far as I can see.

Thanks for the great library.

JohelEGP commented 2 years ago

IIRC, the recommendation is to ask this kind of questions on SO. Maybe https://github.com/ericniebler/range-v3/discussions is also OK.