26 Ranges library [ranges]

26.5 Range utilities [range.utility]

26.5.7 Range conversions [range.utility.conv]

26.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);
Returns: An object of type C constructed from the elements of r in the following manner:
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)...).