boostorg / range

Boost.org range module
http://boost.org/libs/range
42 stars 101 forks source link

Does this library has an analogue of `ranges::views::intersperse`? #139

Open denzor200 opened 1 year ago

denzor200 commented 1 year ago

Can i write some code like this:

#include <range/v3/all.hpp>
#include <vector>
#include <iterator>
#include <algorithm>
#include <iostream>
int main()
{
        auto op = [](auto & input, int i, auto & ins)
        {
            return input | ranges::views::intersperse(ins)
                         | ranges::to<std::string>();
        };
        std::string input{"foobarbaxbat"};
        char insert{','};
        auto rng = op(input, 1, insert);
        std::cout << rng << '\n';      // Outputs: f,o,o,b,a,r,b,a,x,b,a,t
}

without range-v3 library, using Boost.Range instead of range-v3?

denzor200 commented 1 year ago

I tried to do it by myself, like this: https://godbolt.org/z/xb3vMezdb If there is interest in this, I can move forward and make a PR with tests and doc.