ranges::to
is what you want.
Rolling your own semi-replacement is easy.
template<class C, class R>
C to_container( R&& r ) {
using std::begin; using std::end;
return C( begin(std::forward<R>(r)), end(std::forward<R>(r)) );
}
Not library-strength (lacks early failure as the biggest problem, and does not support |
) but quite usable.
and then we just:
std::string r = to_container<std::string>( input | view::remove_if(not_alpha) | view::transform(::tolower) ) | action::sort | action::unique;
Note that taking addresses of functions in std
is no longer advised (via @DavisHerring in a comment above)
To upgrade to |
:
template<class C>
struct to_container_t {
template<class R>
C operator()( R&& r )const {
using std::begin; using std::end;
return C( begin(std::forward<R>(r)), end(std::forward<R>(r)) );
}
template<class R>
friend C operator|( R&& r, to_container_t self ){
return self( std::forward<R>(r) );
}
};
template<class C>
constexpr to_container_t<C> to_container{};
Which gives us:
std::string r = input | view::remove_if(not_alpha) | view::transform(::tolower) | to_container<std::string> | action::sort | action::unique;
As required.