Reference-counted output iterator tuples

std::string foobar;

std::string foobaz;

std::string fooba="fooba";

auto iter=std::copy(fooba.begin(),
		    fooba.end(),
		    x::make_outputrefiterator<char>
                    (std::back_insert_iterator<std::string>(foobar),
                     std::back_insert_iterator<std::string>(foobaz)));

auto tuple_iter=iter.get();

std::back_insert_iterator<std::string>
    a=std::get<0>(tuple_iter->iters);

std::back_insert_iterator<std::string>
    b=std::get<1>(tuple_iter->iters);

*a++='r';
*b++='z';

x::make_outputrefiterator<type>() takes a variadic list iterator over an output sequence of type and instantiates a subclass of x::outputrefiteratorObj<type> returning a x::outputrefiterator to the subclass.

The x::outputrefiteratorObj<type> subclass implements operator=(type) by iterating each iterator that was passed to x::make_outputrefiterator() over the value type. In effect, this splits the output sequence into multiple output sequences, one for each output iterator.

The above example sets foobar to foobar and foobaz to foobaz. Two std::back_insert_iterators get constructed and passed to x::make_outputrefiterator(), that makes an output iterator to which the fooba part gets copied to.

The reference-counted output iterator's get() returns a reference to the underlying reference-counted object. Its iters member is a std::tuple containing the iterators that were passed to x::make_outputrefiterator(). The above example std::get()s the std::back_insert_iterators, then uses them to add the final character to each string.

Note

Using x::make_outputrefiterator() with one output iterator parameter is a convenient way to turn a large output iterator into a reference-counted object.