25 Ranges library [ranges]

25.5 Range utilities [range.utility]

25.5.7 Range conversions [range.utility.conv]

25.5.7.2 ranges​::​to [range.utility.conv.to]

template<class C, input_range R, class... Args> requires (!view<C>) constexpr C to(R&& r, Args&&... args);
Mandates: C is a cv-unqualified class type.
Returns: An object of type C constructed from the elements of r in the following manner:
  • If C does not satisfy input_range or convertible_to<range_reference_t<R>, range_value_t<C>> is true:
  • Otherwise, if input_range<range_reference_t<R>> is true: to<C>(ref_view(r) | views::transform([](auto&& elem) { return to<range_value_t<C>>(std::forward<decltype(elem)>(elem)); }), std::forward<Args>(args)...);
  • Otherwise, the program is ill-formed.
template<template<class...> class C, input_range R, class... Args> constexpr auto to(R&& r, Args&&... args);
Let input-iterator be an exposition-only type: struct input-iterator { // exposition only using iterator_category = input_iterator_tag; using value_type = range_value_t<R>; using difference_type = ptrdiff_t; using pointer = add_pointer_t<range_reference_t<R>>; using reference = range_reference_t<R>; reference operator*() const; pointer operator->() const; input-iterator& operator++(); input-iterator operator++(int); bool operator==(const input-iterator&) const; };
[Note 1: 
input-iterator meets the syntactic requirements of Cpp17InputIterator.
— end note]
Let DEDUCE_EXPR be defined as follows:
  • C(declval<R>(), declval<Args>()...) if that is a valid expression,
  • otherwise, C(from_range, declval<R>(), declval<Args>()...) if that is a valid expression,
  • otherwise, C(declval<input-iterator>(), declval<input-iterator>(), declval<Args>()...) if that is a valid expression,
  • otherwise, the program is ill-formed.
Returns: to<decltype(DEDUCE_EXPR)>(std​::​forward<R>(r), std​::​forward<Args>(args)...).