The range conversion functions construct
an object (usually a container) from a range,
by using a constructor taking a range,
a from_range_t tagged constructor, or
a constructor taking a pair of iterators, or
by inserting each element of the range into the default-constructed object.
ranges::to is applied recursively,
allowing the conversion of a range of ranges.
[Example 1: string_view str ="the quick brown fox";
auto words = views::split(str, ' ')| to<vector<string>>();
// words is vector<string>{"the", "quick", "brown", "fox"} — end example]
Let reservable-container be defined as follows:
template<class Container>constexprboolreservable-container=// exposition onlysized_range<Container>&&requires(Container& c, range_size_t<Container> n){
c.reserve(n);
{ c.capacity()}->same_as<decltype(n)>;
{ c.max_size()}->same_as<decltype(n)>;
};
Let container-insertable be defined as follows:
template<class Container, class Ref>constexprboolcontainer-insertable=// exposition onlyrequires(Container& c, Ref&& ref){requires(requires{ c.push_back(std::forward<Ref>(ref)); }||requires{ c.insert(c.end(), std::forward<Ref>(ref)); });
};
Let container-inserter be defined as follows:
template<class Ref, class Container>constexprautocontainer-inserter(Container& c){// exposition onlyifconstexpr(requires{ c.push_back(declval<Ref>()); })return back_inserter(c);
elsereturn inserter(c, c.end());
}
Returns: A range adaptor closure object ([range.adaptor.object]) f
that is a perfect forwarding call wrapper ([func.require])
with the following properties:
Its bound argument entities bound_args consist of
objects of types decay_t<Args>...
direct-non-list-initialized with std::forward<Args>(args)...,
respectively.