[range.to.input]

# 25 Ranges library [[ranges]](./#ranges)

## 25.7 Range adaptors [[range.adaptors]](range.adaptors#range.to.input)

### 25.7.35 To input view [range.to.input]

#### [25.7.35.1](#overview) Overview [[range.to.input.overview]](range.to.input.overview)

[1](#overview-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L17722)

to_input_view presents a view of an underlying sequence
as an input-only non-common range[.](#overview-1.sentence-1)

[*Note [1](#overview-note-1)*:

This is useful to avoid overhead
that can be necessary to provide support for the operations
needed for greater iterator strength[.](#overview-1.sentence-2)

â *end note*]

[2](#overview-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L17731)

The name views​::​to_input denotes
a range adaptor object ([[range.adaptor.object]](range.adaptor.object "25.7.2 Range adaptor objects"))[.](#overview-2.sentence-1)

Let E be an expression and let T be decltype((E))[.](#overview-2.sentence-2)

The expression views​::​to_input(E) is expression-equivalent to:

- [(2.1)](#overview-2.1)

  views​::​all(E) if T models [input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]"),
does not satisfy [common_range](range.refinements#concept:common_range "25.4.6 Other range refinements [range.refinements]"), and
does not satisfy [forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]")[.](#overview-2.1.sentence-1)

- [(2.2)](#overview-2.2)

  Otherwise, to_input_view(E)[.](#overview-2.2.sentence-1)

#### [25.7.35.2](#view) Class template to_input_view [[range.to.input.view]](range.to.input.view)

[ð](#lib:to_input_view)

namespace std::ranges {template<[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") V>requires [view](range.view#concept:view "25.4.5 Views [range.view]")<V>class to_input_view : public view_interface<to_input_view<V>> { V *base_* = V(); // *exposition only*// [[range.to.input.iterator]](#iterator "25.7.35.3 Class template to_­input_­view​::​iterator"), class template to_input_view​::​*iterator*template<bool Const> class *iterator*; // *exposition only*public: to_input_view() requires [default_initializable](concept.default.init#concept:default_initializable "18.4.12 Concept default_­initializable [concept.default.init]")<V> = default; constexpr explicit to_input_view(V base); constexpr V base() const & requires [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14 Concept copy_­constructible [concept.copyconstructible]")<V> { return *base_*; }constexpr V base() && { return std::move(*base_*); }constexpr auto begin() requires (![*simple-view*](range.utility.helpers#concept:simple-view "25.5.2 Helper concepts [range.utility.helpers]")<V>); constexpr auto begin() const requires [range](range.range#concept:range "25.4.2 Ranges [range.range]")<const V>; constexpr auto end() requires (![*simple-view*](range.utility.helpers#concept:simple-view "25.5.2 Helper concepts [range.utility.helpers]")<V>); constexpr auto end() const requires [range](range.range#concept:range "25.4.2 Ranges [range.range]")<const V>; constexpr auto size() requires [sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]")<V>; constexpr auto size() const requires [sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]")<const V>; constexpr auto reserve_hint() requires [approximately_sized_range](range.approximately.sized#concept:approximately_sized_range "25.4.3 Approximately sized ranges [range.approximately.sized]")<V>; constexpr auto reserve_hint() const requires [approximately_sized_range](range.approximately.sized#concept:approximately_sized_range "25.4.3 Approximately sized ranges [range.approximately.sized]")<const V>; }; template<class R> to_input_view(R&&) -> to_input_view<views::all_t<R>>;}

[ð](#lib:to_input_view,constructor)

`constexpr explicit to_input_view(V base);
`

[1](#view-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L17790)

*Effects*: Initializes *base_* with std​::​move(base)[.](#view-1.sentence-1)

[ð](#lib:begin,to_input_view)

`constexpr auto begin() requires (![simple-view](range.utility.helpers#concept:simple-view "25.5.2 Helper concepts [range.utility.helpers]")<V>);
`

[2](#view-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L17801)

*Effects*: Equivalent to: return *iterator*<false>(ranges​::​begin(*base_*));

[ð](#lib:begin,to_input_view_)

`constexpr auto begin() const requires [range](range.range#concept:range "25.4.2 Ranges [range.range]")<const V>;
`

[3](#view-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L17812)

*Effects*: Equivalent to: return *iterator*<true>(ranges​::​begin(*base_*));

[ð](#lib:end,to_input_view)

`constexpr auto end() requires (![simple-view](range.utility.helpers#concept:simple-view "25.5.2 Helper concepts [range.utility.helpers]")<V>);
constexpr auto end() const requires [range](range.range#concept:range "25.4.2 Ranges [range.range]")<const V>;
`

[4](#view-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L17824)

*Effects*: Equivalent to: return ranges​::​end(*base_*);

[ð](#lib:size,to_input_view)

`constexpr auto size() requires [sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]")<V>;
constexpr auto size() const requires [sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]")<const V>;
`

[5](#view-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L17836)

*Effects*: Equivalent to: return ranges​::​size(*base_*);

[ð](#lib:reserve_hint,to_input_view)

`constexpr auto reserve_hint() requires [approximately_sized_range](range.approximately.sized#concept:approximately_sized_range "25.4.3 Approximately sized ranges [range.approximately.sized]")<V>;
constexpr auto reserve_hint() const requires [approximately_sized_range](range.approximately.sized#concept:approximately_sized_range "25.4.3 Approximately sized ranges [range.approximately.sized]")<const V>;
`

[6](#view-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L17848)

*Effects*: Equivalent to: return ranges​::​reserve_hint(*base_*);

#### [25.7.35.3](#iterator) Class template to_input_view​::​*iterator* [[range.to.input.iterator]](range.to.input.iterator)

[ð](#lib:to_input_view::iterator)

namespace std::ranges {template<[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") V>requires [view](range.view#concept:view "25.4.5 Views [range.view]")<V>template<bool Const>class to_input_view<V>::*iterator* {using *Base* = *maybe-const*<Const, V>; // *exposition only* iterator_t<*Base*> *current_* = iterator_t<*Base*>(); // *exposition only*constexpr explicit *iterator*(iterator_t<*Base*> current); // *exposition only*public:using difference_type = range_difference_t<*Base*>; using value_type = range_value_t<*Base*>; using iterator_concept = input_iterator_tag; *iterator*() requires [default_initializable](concept.default.init#concept:default_initializable "18.4.12 Concept default_­initializable [concept.default.init]")<iterator_t<*Base*>> = default; *iterator*(*iterator*&&) = default; *iterator*& operator=(*iterator*&&) = default; constexpr *iterator*(*iterator*<!Const> i)requires Const && [convertible_to](concept.convertible#concept:convertible_to "18.4.4 Concept convertible_­to [concept.convertible]")<iterator_t<V>, iterator_t<*Base*>>; constexpr iterator_t<*Base*> base() &&; constexpr const iterator_t<*Base*>& base() const & noexcept; constexpr decltype(auto) operator*() const { return **current_*; }constexpr *iterator*& operator++(); constexpr void operator++(int); friend constexpr bool operator==(const *iterator*& x, const sentinel_t<*Base*>& y); friend constexpr difference_type operator-(const sentinel_t<*Base*>& y, const *iterator*& x)requires [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]")<sentinel_t<*Base*>, iterator_t<*Base*>>; friend constexpr difference_type operator-(const *iterator*& x, const sentinel_t<*Base*>& y)requires [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]")<sentinel_t<*Base*>, iterator_t<*Base*>>; friend constexpr range_rvalue_reference_t<*Base*> iter_move(const *iterator*& i)noexcept(noexcept(ranges::iter_move(i.*current_*))); friend constexpr void iter_swap(const *iterator*& x, const *iterator*& y)noexcept(noexcept(ranges::iter_swap(x.*current_*, y.*current_*)))requires [indirectly_swappable](alg.req.ind.swap#concept:indirectly_swappable "24.3.7.4 Concept indirectly_­swappable [alg.req.ind.swap]")<iterator_t<*Base*>>; };}

[ð](#lib:to_input_view::iterator,constructor)

`constexpr explicit iterator(iterator_t<Base> current);
`

[1](#iterator-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L17912)

*Effects*: Initializes *current_* with std​::​move(current)[.](#iterator-1.sentence-1)

[ð](#lib:to_input_view::iterator,constructor_)

`constexpr iterator(iterator<!Const> i)
  requires Const && [convertible_to](concept.convertible#concept:convertible_to "18.4.4 Concept convertible_­to [concept.convertible]")<iterator_t<V>, iterator_t<Base>>;
`

[2](#iterator-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L17924)

*Effects*: Initializes *current_* with std​::​move(i.*current_*)[.](#iterator-2.sentence-1)

[ð](#lib:base,to_input_view::iterator)

`constexpr iterator_t<Base> base() &&;
`

[3](#iterator-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L17935)

*Returns*: std​::​move(*current_)*[.](#iterator-3.sentence-1)

[ð](#lib:base,to_input_view::iterator_)

`constexpr const iterator_t<Base>& base() const & noexcept;
`

[4](#iterator-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L17946)

*Returns*: *current_*[.](#iterator-4.sentence-1)

[ð](#lib:operator++,to_input_view::iterator)

`constexpr iterator& operator++();
`

[5](#iterator-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L17957)

*Effects*: Equivalent to:++*current_*;return *this;

[ð](#lib:operator++,to_input_view::iterator_)

`constexpr void operator++(int);
`

[6](#iterator-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L17972)

*Effects*: Equivalent to: ++*this;

[ð](#lib:operator==,to_input_view::iterator)

`friend constexpr bool operator==(const iterator& x, const sentinel_t<Base>& y);
`

[7](#iterator-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L17983)

*Returns*: x.*current_* == y[.](#iterator-7.sentence-1)

[ð](#lib:operator-,to_input_view::iterator)

`friend constexpr difference_type operator-(const sentinel_t<Base>& y, const iterator& x)
  requires [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]")<sentinel_t<Base>, iterator_t<Base>>;
`

[8](#iterator-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L17995)

*Returns*: y - x.*current_*[.](#iterator-8.sentence-1)

[ð](#lib:operator-,to_input_view::iterator_)

`friend constexpr difference_type operator-(const iterator& x, const sentinel_t<Base>& y)
  requires [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]")<sentinel_t<Base>, iterator_t<Base>>;
`

[9](#iterator-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L18007)

*Returns*: x.*current_* - y[.](#iterator-9.sentence-1)

[ð](#lib:iter_move,to_input_view::iterator)

`friend constexpr range_rvalue_reference_t<Base> iter_move(const iterator& i)
  noexcept(noexcept(ranges::iter_move(i.current_)));
`

[10](#iterator-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L18019)

*Effects*: Equivalent to: return ranges​::​iter_move(i.*current_*);

[ð](#lib:iter_swap,to_input_view::iterator)

`friend constexpr void iter_swap(const iterator& x, const iterator& y)
  noexcept(noexcept(ranges::iter_swap(x.current_, y.current_)))
  requires [indirectly_swappable](alg.req.ind.swap#concept:indirectly_swappable "24.3.7.4 Concept indirectly_­swappable [alg.req.ind.swap]")<iterator_t<Base>>;
`

[11](#iterator-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L18032)

*Effects*: Equivalent to: ranges​::​iter_swap(x.*current_*, y.*current_*);
