Standard library header - cppreference.com (original) (raw)
This header is part of the iterator library.
| This header is a partial freestanding header. Everything inside this header is freestanding beside stream iterators. | (since C++23) |
|---|
| Contents 1 Concepts 1.1 Iterator concepts 1.2 Indirect callable concepts 1.3 Common algorithm requirements 2 Classes 2.1 Algorithm utilities 2.2 Associated types 2.3 Primitives 2.4 Adaptors 2.5 Stream Iterators 3 Customization point objects 4 Constants 5 Functions 5.1 Adaptors 5.2 Non-member operators 5.3 Operations 5.4 Range access 6 Synopsis 6.1 Concept indirectly_readable 6.2 Concept indirectly_writable 6.3 Concept weakly_incrementable 6.4 Concept incrementable 6.5 Concept input_or_output_iterator 6.6 Concept sentinel_for 6.7 Concept sized_sentinel_for 6.8 Concept input_iterator 6.9 Concept output_iterator 6.10 Concept forward_iterator 6.11 Concept bidirectional_iterator 6.12 Concept random_access_iterator 6.13 Concept contiguous_iterator 6.14 Concept indirectly_unary_invocable 6.15 Concept indirectly_regular_unary_invocable 6.16 Concept indirect_unary_predicate 6.17 Concept indirect_binary_predicate 6.18 Concept indirect_equivalence_relation 6.19 Concept indirect_strict_weak_order 6.20 Concept indirectly_movable 6.21 Concept indirectly_movable_storable 6.22 Concept indirectly_copyable 6.23 Concept indirectly_copyable_storable 6.24 Concept indirectly_swappable 6.25 Concept indirectly_comparable 6.26 Concept permutable 6.27 Concept mergeable 6.28 Concept sortable 6.29 Class template std::incrementable_traits 6.30 Class template std::indirectly_readable_traits 6.31 Class template std::projected 6.32 Class template std::iterator_traits 6.33 Iterator tags 6.34 Class template std::reverse_iterator 6.35 Class template std::back_insert_iterator 6.36 Class template std::front_insert_iterator 6.37 Class template std::insert_iterator 6.38 Class template std::move_iterator 6.39 Class template std::move_sentinel 6.40 Class template std::common_iterator 6.41 Class std::default_sentinel_t 6.42 Class template std::counted_iterator 6.43 Class std::unreachable_sentinel_t 6.44 Class template std::istream_iterator 6.45 Class template std::ostream_iterator 6.46 Class template std::istreambuf_iterator 6.47 Class template std::ostreambuf_iterator 6.48 Class template std::iterator 7 Defect reports Concepts | |
|---|---|
| Iterator concepts | |
| specifies that a type is indirectly readable by applying operator * (concept) [edit] | |
| specifies that a value can be written to an iterator's referenced object (concept) [edit] | |
| specifies that a semiregular type can be incremented with pre- and post-increment operators (concept) [edit] | |
| specifies that the increment operation on a weakly_incrementable type is equality-preserving and that the type is equality_comparable (concept) [edit] | |
| specifies that objects of a type can be incremented and dereferenced (concept) [edit] | |
| specifies a type is a sentinel for an input_or_output_iterator type (concept) [edit] | |
| specifies that the - operator can be applied to an iterator and a sentinel to calculate their difference in constant time (concept) [edit] | |
| specifies that a type is an input iterator, that is, its referenced values can be read and it can be both pre- and post-incremented (concept) [edit] | |
| specifies that a type is an output iterator for a given value type, that is, values of that type can be written to it and it can be both pre- and post-incremented (concept) [edit] | |
| specifies that an input_iterator is a forward iterator, supporting equality comparison and multi-pass (concept) [edit] | |
| specifies that a forward_iterator is a bidirectional iterator, supporting movement backwards (concept) [edit] | |
| specifies that a bidirectional_iterator is a random-access iterator, supporting advancement in constant time and subscripting (concept) [edit] | |
| specifies that a random_access_iterator is a contiguous iterator, referring to elements that are contiguous in memory (concept) [edit] | |
| Indirect callable concepts | |
| specifies that a callable type can be invoked with the result of dereferencing an indirectly_readable type (concept) [edit] | |
| specifies that a callable type, when invoked with the result of dereferencing an indirectly_readable type, satisfies predicate (concept) [edit] | |
| specifies that a callable type, when invoked with the result of dereferencing two indirectly_readable types, satisfies predicate (concept) [edit] | |
| specifies that a callable type, when invoked with the result of dereferencing two indirectly_readable types, satisfies equivalence_relation (concept) [edit] | |
| specifies that a callable type, when invoked with the result of dereferencing two indirectly_readable types, satisfies strict_weak_order (concept) [edit] | |
| Common algorithm requirements | |
| specifies that values may be moved from an indirectly_readable type to an indirectly_writable type (concept) [edit] | |
| specifies that values may be moved from an indirectly_readable type to an indirectly_writable type and that the move may be performed via an intermediate object (concept) [edit] | |
| specifies that values may be copied from an indirectly_readable type to an indirectly_writable type (concept) [edit] | |
| specifies that values may be copied from an indirectly_readable type to an indirectly_writable type and that the copy may be performed via an intermediate object (concept) [edit] | |
| specifies that the values referenced by two indirectly_readable types can be swapped (concept) [edit] | |
| specifies that the values referenced by two indirectly_readable types can be compared (concept) [edit] | |
| specifies the common requirements of algorithms that reorder elements in place (concept) [edit] | |
| specifies the requirements of algorithms that merge sorted sequences into an output sequence by copying elements (concept) [edit] | |
| specifies the common requirements of algorithms that permute sequences into ordered sequences (concept) [edit] | |
| Classes | |
| Algorithm utilities | |
| computes the result of invoking a callable object on the result of dereferencing some set of indirectly_readable types(alias template)[edit] | |
| helper template for specifying the constraints on algorithms that accept projections(alias template)[edit] | |
| computes the value type of an indirectly_readable type by projection(alias template)[edit] | |
| Associated types | |
| computes the difference type of a weakly_incrementable type (class template) [edit] | |
| computes the value type of an indirectly_readable type (class template) [edit] | |
| (C++20)(C++20)(C++23)(C++20)(C++20)(C++20) | computes the associated types of an iterator(alias template)[edit] |
| Primitives | |
| provides uniform interface to the properties of an iterator (class template) [edit] | |
| empty class types used to indicate iterator categories (class) [edit] | |
| base class to ease the definition of required types for simple iterators (class template) [edit] | |
| Adaptors | |
| iterator adaptor for reverse-order traversal (class template) [edit] | |
| iterator adaptor which dereferences to an rvalue (class template) [edit] | |
| sentinel adaptor for std::move_iterator (class template) [edit] | |
| iterator adaptor that converts an iterator into a constant iterator (class template) [edit] | |
| computes a constant iterator type for a given type(alias template)[edit] | |
| computes a sentinel type to be used with constant iterators(alias template)[edit] | |
| adapts an iterator type and its sentinel into a common iterator type (class template) [edit] | |
| default sentinel for use with iterators that know the bound of their range (class) [edit] | |
| iterator adaptor that tracks the distance to the end of the range (class template) [edit] | |
| sentinel that always compares unequal to any weakly_incrementable type (class) [edit] | |
| iterator adaptor for insertion at the end of a container (class template) [edit] | |
| iterator adaptor for insertion at the front of a container (class template) [edit] | |
| iterator adaptor for insertion into a container (class template) [edit] | |
| Stream Iterators | |
| input iterator that reads from std::basic_istream (class template) [edit] | |
| output iterator that writes to std::basic_ostream (class template) [edit] | |
| input iterator that reads from std::basic_streambuf (class template) [edit] | |
| output iterator that writes to std::basic_streambuf (class template) [edit] | |
| Customization point objects | |
| Defined in namespace std::ranges | |
| casts the result of dereferencing an object to its associated rvalue reference type(customization point object)[edit] | |
| swaps the values referenced by two dereferenceable objects(customization point object)[edit] | |
| Constants | |
| an object of type unreachable_sentinel_t that always compares unequal to any weakly_incrementable type (constant) [edit] | |
| an object of type default_sentinel_t used with iterators that know the bound of their range (constant) [edit] | |
| Functions | |
| Adaptors | |
| creates a std::reverse_iterator of type inferred from the argument (function template) [edit] | |
| creates a std::move_iterator of type inferred from the argument (function template) [edit] | |
| creates a std::const_iterator of type inferred from the argument (function template) [edit] | |
| creates a std::const_sentinel of type inferred from the argument (function template) [edit] | |
| creates a std::front_insert_iterator of type inferred from the argument (function template) [edit] | |
| creates a std::back_insert_iterator of type inferred from the argument (function template) [edit] | |
| creates a std::insert_iterator of type inferred from the argument (function template) [edit] | |
| Non-member operators | |
| (C++11)(C++11)(removed in C++20)(C++11)(C++11)(C++11)(C++11)(C++20) | compares the underlying iterators (function template) [edit] |
| advances the iterator (function template) [edit] | |
| computes the distance between two iterator adaptors (function template) [edit] | |
| compares the underlying iterators (function template) [edit] | |
| advances the iterator (function template) [edit] | |
| computes the distance between two iterator adaptors (function template) [edit] | |
| compares the distances to the end (function template) [edit] | |
| advances the iterator (function template) [edit] | |
| computes the distance between two iterator adaptors (function template) [edit] | |
| compares two istream_iterators (function template) [edit] | |
| compares two istreambuf_iterators (function template) [edit] | |
| Operations | |
| advances an iterator by given distance (function template) [edit] | |
| returns the distance between two iterators (function template) [edit] | |
| increment an iterator (function template) [edit] | |
| decrement an iterator (function template) [edit] | |
| advances an iterator by given distance or to a given bound(algorithm function object)[edit] | |
| returns the distance between an iterator and a sentinel, or between the beginning and end of a range(algorithm function object)[edit] | |
| increment an iterator by a given distance or to a bound(algorithm function object)[edit] | |
| decrement an iterator by a given distance or to a bound(algorithm function object)[edit] | |
| Range access | |
| returns an iterator to the beginning of a container or array (function template) [edit] | |
| returns an iterator to the end of a container or array (function template) [edit] | |
| returns a reverse iterator to the beginning of a container or array (function template) [edit] | |
| returns a reverse end iterator for a container or array (function template) [edit] | |
| returns the size of a container or array (function template) [edit] | |
| checks whether the container is empty (function template) [edit] | |
| obtains the pointer to the underlying array (function template) [edit] |
[edit] Synopsis
#include #include namespace std { template using /* with-reference / = T&; // exposition only template concept / can-reference / // exposition only = requires { typename / with-reference /; }; template concept / dereferenceable / // exposition only = requires(T& t) { { t } -> / can-reference /; // not required to be equality-preserving }; // associated types // incrementable traits template struct incrementable_traits; template using iter_difference_t = / see description /; // indirectly readable traits template struct indirectly_readable_traits; template using iter_value_t = / see description /; // iterator traits template struct iterator_traits; template requires is_object_v struct iterator_traits<T*>; template</* dereferenceable */ T> using iter_reference_t = decltype(declval<T&>()); namespace ranges { // customization point objects inline namespace / unspecified / { // ranges::iter_move inline constexpr / unspecified / iter_move = / unspecified /; // ranges::iter_swap inline constexpr / unspecified / iter_swap = / unspecified /; } } template</* dereferenceable */ T> requires requires(T& t) { { ranges::iter_move(t) } -> / can-reference /; } using iter_rvalue_reference_t = decltype(ranges::iter_move(declval<T&>())); // iterator concepts // concept indirectly_readable template concept indirectly_readable = / see description /; template using iter_common_reference_t = common_reference_t<iter_reference_t, iter_value_t&>; // concept indirectly_writable template<class Out, class T> concept indirectly_writable = / see description /; // concept weakly_incrementable template concept weakly_incrementable = / see description /; // concept incrementable template concept incrementable = / see description /; // concept input_or_output_iterator template concept input_or_output_iterator = / see description /; // concept sentinel_for template<class S, class I> concept sentinel_for = / see description /; // concept sized_sentinel_for template<class S, class I> inline constexpr bool disable_sized_sentinel_for = false; template<class S, class I> concept sized_sentinel_for = / see description /; // concept input_iterator template concept input_iterator = / see description /; // concept output_iterator template<class I, class T> concept output_iterator = / see description /; // concept forward_iterator template concept forward_iterator = / see description /; // concept bidirectional_iterator template concept bidirectional_iterator = / see description /; // concept random_access_iterator template concept random_access_iterator = / see description /; // concept contiguous_iterator template concept contiguous_iterator = / see description /; // indirect callable requirements // indirect callables template<class F, class I> concept indirectly_unary_invocable = / see description /; template<class F, class I> concept indirectly_regular_unary_invocable = / see description /; template<class F, class I> concept indirect_unary_predicate = / see description /; template<class F, class I1, class I2> concept indirect_binary_predicate = / see description /; template<class F, class I1, class I2 = I1> concept indirect_equivalence_relation = / see description /; template<class F, class I1, class I2 = I1> concept indirect_strict_weak_order = / see description /; template<class F, class... Is> requires (indirectly_readable && ...) && invocable<F, iter_reference_t...> using indirect_result_t = invoke_result_t<F, iter_reference_t...>; // projected template<indirectly_readable I, indirectly_regular_unary_invocable Proj> using projected = / see description /; template<indirectly_readable I, indirectly_regular_unary_invocable Proj> using projected_value_t = remove_cvref_t<invoke_result_t<Proj&, iter_value_t&>>; // common algorithm requirements // concept indirectly_movable template<class In, class Out> concept indirectly_movable = / see description /; template<class In, class Out> concept indirectly_movable_storable = / see description /; // concept indirectly_copyable template<class In, class Out> concept indirectly_copyable = / see description /; template<class In, class Out> concept indirectly_copyable_storable = / see description /; // concept indirectly_swappable template<class I1, class I2 = I1> concept indirectly_swappable = / see description /; // concept indirectly_comparable template<class I1, class I2, class R, class P1 = identity, class P2 = identity> concept indirectly_comparable = / see description /; // concept permutable template concept permutable = / see description /; // concept mergeable template<class I1, class I2, class Out, class R = ranges::less, class P1 = identity, class P2 = identity> concept mergeable = / see description /; // concept sortable template<class I, class R = ranges::less, class P = identity> concept sortable = / see description /; // primitives // iterator tags struct input_iterator_tag { }; struct output_iterator_tag { }; struct forward_iterator_tag: public input_iterator_tag { }; struct bidirectional_iterator_tag: public forward_iterator_tag { }; struct random_access_iterator_tag: public bidirectional_iterator_tag { }; struct contiguous_iterator_tag: public random_access_iterator_tag { }; // iterator operations template<class InputIt, class Distance> constexpr void advance(InputIt& i, Distance n); template constexpr typename iterator_traits::difference_type distance(InputIt first, InputIt last); template constexpr InputIt next(InputIt x, typename iterator_traits::difference_type n = 1); template constexpr BidirIt prev(BidirIt x, typename iterator_traits::difference_type n = 1); // range iterator operations namespace ranges { // ranges::advance template constexpr void advance(I& i, iter_difference_t n); template<input_or_output_iterator I, sentinel_for S> constexpr void advance(I& i, S bound); template<input_or_output_iterator I, sentinel_for S> constexpr iter_difference_t advance(I& i, iter_difference_t n, S bound); // ranges::distance template<class I, sentinel_for S> requires (!sized_sentinel_for<S, I>) constexpr iter_difference_t distance(I first, S last); template<class I, sized_sentinel_for<decay_t> S> constexpr iter_difference_t<decay_t> distance(I&& first, S last); template constexpr range_difference_t distance(R&& r); // ranges::next template constexpr I next(I x); template constexpr I next(I x, iter_difference_t n); template<input_or_output_iterator I, sentinel_for S> constexpr I next(I x, S bound); template<input_or_output_iterator I, sentinel_for S> constexpr I next(I x, iter_difference_t n, S bound); // ranges::prev template constexpr I prev(I x); template constexpr I prev(I x, iter_difference_t n); template constexpr I prev(I x, iter_difference_t n, I bound); } // predefined iterators and sentinels // reverse iterators template class reverse_iterator; template<class It1, class It2> constexpr bool operator==(const reverse_iterator& x, const reverse_iterator& y); template<class It1, class It2> constexpr bool operator!=(const reverse_iterator& x, const reverse_iterator& y); template<class It1, class It2> constexpr bool operator<(const reverse_iterator& x, const reverse_iterator& y); template<class It1, class It2> constexpr bool operator>(const reverse_iterator& x, const reverse_iterator& y); template<class It1, class It2> constexpr bool operator<=(const reverse_iterator& x, const reverse_iterator& y); template<class It1, class It2> constexpr bool operator>=(const reverse_iterator& x, const reverse_iterator& y); template<class It1, three_way_comparable_with It2> constexpr compare_three_way_result_t<It1, It2> operator<=>(const reverse_iterator& x, const reverse_iterator& y); template<class It1, class It2> constexpr auto operator-(const reverse_iterator& x, const reverse_iterator& y) -> decltype(y.base() - x.base()); template constexpr reverse_iterator operator+(iter_difference_t n, const reverse_iterator& x); template constexpr reverse_iterator make_reverse_iterator(It i); template<class It1, class It2> requires (!sized_sentinel_for<It1, It2>) inline constexpr bool disable_sized_sentinel_for<reverse_iterator, reverse_iterator> = true; // insert iterators template class back_insert_iterator; template constexpr back_insert_iterator back_inserter(Container& x); template class front_insert_iterator; template constexpr front_insert_iterator front_inserter(Container& x); template class insert_iterator; template constexpr insert_iterator inserter(Container& x, ranges::iterator_t i); // move iterators and sentinels template class move_iterator; template<class It1, class It2> constexpr bool operator==(const move_iterator& x, const move_iterator& y); template<class It1, class It2> constexpr bool operator<(const move_iterator& x, const move_iterator& y); template<class It1, class It2> constexpr bool operator>(const move_iterator& x, const move_iterator& y); template<class It1, class It2> constexpr bool operator<=(const move_iterator& x, const move_iterator& y); template<class It1, class It2> constexpr bool operator>=(const move_iterator& x, const move_iterator& y); template<class It1, three_way_comparable_with It2> constexpr compare_three_way_result_t<It1, It2> operator<=>(const move_iterator& x, const move_iterator& y); template<class It1, class It2> constexpr auto operator-(const move_iterator& x, const move_iterator& y) -> decltype(x.base() - y.base()); template constexpr move_iterator operator+(iter_difference_t n, const move_iterator& x); template constexpr move_iterator make_move_iterator(It i); template class move_sentinel; // common iterators template<input_or_output_iterator I, sentinel_for S> requires (!same_as<I, S> && copyable) class common_iterator; template<class I, class S> struct incrementable_traits<common_iterator<I, S>>; template<input_iterator I, class S> struct iterator_traits<common_iterator<I, S>>; // default sentinel struct default_sentinel_t; inline constexpr default_sentinel_t default_sentinel{}; // counted iterators template class counted_iterator; template requires / see description / struct iterator_traits<counted_iterator>; // unreachable sentinel struct unreachable_sentinel_t; inline constexpr unreachable_sentinel_t unreachable_sentinel{}; // stream iterators template<class T, class CharT = char, class Traits = char_traits, class Distance = ptrdiff_t> class istream_iterator; template<class T, class CharT, class Traits, class Distance> bool operator==(const istream_iterator<T, CharT, Traits, Distance>& x, const istream_iterator<T, CharT, Traits, Distance>& y); template<class T, class CharT = char, class traits = char_traits> class ostream_iterator; template<class CharT, class Traits = char_traits> class istreambuf_iterator; template<class CharT, class Traits> bool operator==(const istreambuf_iterator<CharT, Traits>& a, const istreambuf_iterator<CharT, Traits>& b); template<class CharT, class Traits = char_traits> class ostreambuf_iterator; // range access template constexpr auto begin(C& c) -> decltype(c.begin()); template constexpr auto begin(const C& c) -> decltype(c.begin()); template constexpr auto end(C& c) -> decltype(c.end()); template constexpr auto end(const C& c) -> decltype(c.end()); template<class T, size_t N> constexpr T begin(T (&a)[N]) noexcept; template<class T, size_t N> constexpr T end(T (&a)[N]) noexcept; template constexpr auto cbegin(const C& c) noexcept(noexcept(std::begin(c))) -> decltype(std::begin(c)); template constexpr auto cend(const C& c) noexcept(noexcept(std::end(c))) -> decltype(std::end(c)); template constexpr auto rbegin(C& c) -> decltype(c.rbegin()); template constexpr auto rbegin(const C& c) -> decltype(c.rbegin()); template constexpr auto rend(C& c) -> decltype(c.rend()); template constexpr auto rend(const C& c) -> decltype(c.rend()); template<class T, size_t N> constexpr reverse_iterator<T*> rbegin(T (&a)[N]); template<class T, size_t N> constexpr reverse_iterator<T*> rend(T (&a)[N]); template constexpr reverse_iterator<const E*> rbegin(initializer_list il); template constexpr reverse_iterator<const E*> rend(initializer_list il); template constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); template constexpr auto crend(const C& c) -> decltype(std::rend(c)); template constexpr auto size(const C& c) -> decltype(c.size()); template<class T, size_t N> constexpr size_t size(const T (&a)[N]) noexcept; template constexpr auto ssize(const C& c) -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; template<class T, ptrdiff_t N> constexpr ptrdiff_t ssize(const T (&a)[N]) noexcept; template constexpr auto empty(const C& c) -> decltype(c.empty()); template<class T, size_t N> constexpr bool empty(const T (&a)[N]) noexcept; template constexpr bool empty(initializer_list il) noexcept; template constexpr auto data(C& c) -> decltype(c.data()); template constexpr auto data(const C& c) -> decltype(c.data()); template<class T, size_t N> constexpr T data(T (&a)[N]) noexcept; template constexpr const E* data(initializer_list il) noexcept; }
[edit] Concept indirectly_readable
namespace std { template concept /indirectlyReadableImpl/ = // exposition only requires(const In in) { typename iter_value_t; typename iter_reference_t; typename iter_rvalue_reference_t; { *in } -> same_as<iter_reference_t> { iter_move(in) } -> same_as<iter_rvalue_reference_t> } && common_reference_with<iter_reference_t&&, iter_value_t&> && common_reference_with<iter_reference_t&&, iter_rvalue_reference_t&&> && common_reference_with<iter_rvalue_reference_t&&, const iter_value_t&>; template concept indirectly_readable = /indirectlyReadableImpl/<remove_cvref_t> }
[edit] Concept indirectly_writable
namespace std { template<class Out, class T> concept indirectly_writable = requires(Out&& o, T&& t) { *o = std::forward(t); // not required to be equality-preserving *std::forward(o) = std::forward(t); // not required to be equality-preserving const_cast<const iter_reference_t&&>(o) = std::forward(t); // not required to be equality-preserving const_cast<const iter_reference_t&&>(std::forward(o)) = std::forward(t); // not required to be equality-preserving }; }
[edit] Concept weakly_incrementable
namespace std { template inline constexpr bool /is_integer_like/ = /* see description /; // exposition only template inline constexpr bool /is_signed_integer_like/ = // exposition only / see description */; template concept weakly_incrementable = default_initializable && movable && requires(I i) { typename iter_difference_t; requires /is_signed_integer_like/<iter_difference_t>; { ++i } -> same_as<I&>; // not required to be equality-preserving i++; // not required to be equality-preserving }; }
[edit] Concept incrementable
namespace std { template concept incrementable = regular && weakly_incrementable && requires(I i) { { i++ } -> same_as; }; }
[edit] Concept input_or_output_iterator
namespace std { template concept input_or_output_iterator = requires(I i) { { *i } -> can-reference; } && weakly_incrementable; }
[edit] Concept sentinel_for
namespace std {
template<class S, class I>
concept sentinel_for =
semiregular &&
input_or_output_iterator &&
/WeaklyEqualityComparableWith/<S, I>;
}
[edit] Concept sized_sentinel_for
namespace std {
template<class S, class I>
concept sized_sentinel_for =
sentinel_for<S, I> &&
!disable_sized_sentinel<remove_cv_t, remove_cv_t> &&
requires(const I& i, const S& s) {
{ s - i } -> same_as<iter_difference_t>;
{ i - s } -> same_as<iter_difference_t>;
};
}
[edit] Concept input_iterator
namespace std { template concept input_iterator = input_or_output_iterator && indirectly_readable && requires { typename /* ITER_CONCEPT */(I); } && derived_from</* ITER_CONCEPT */(I), input_iterator_tag>; }
[edit] Concept output_iterator
namespace std { template<class I, class T> concept output_iterator = input_or_output_iterator && indirectly_writable<I, T> && requires(I i, T&& t) { *i++ = std::forward(t); // not required to be equality-preserving }; }
[edit] Concept forward_iterator
namespace std { template concept forward_iterator = input_iterator && derived_from</* ITER_CONCEPT */(I), forward_iterator_tag> && incrementable && sentinel_for<I, I>; }
[edit] Concept bidirectional_iterator
namespace std { template concept bidirectional_iterator = forward_iterator && derived_from</* ITER_CONCEPT */(I), bidirectional_iterator_tag> && requires(I i) { { --i } -> same_as<I&>; { i-- } -> same_as; }; }
[edit] Concept random_access_iterator
namespace std { template concept random_access_iterator = bidirectional_iterator && derived_from</* ITER_CONCEPT */(I), random_access_iterator_tag> && totally_ordered && sized_sentinel_for<I, I> && requires(I i, const I j, const iter_difference_t n) { { i += n } -> same_as<I&>; { j + n } -> same_as; { n + j } -> same_as; { i -= n } -> same_as<I&>; { j - n } -> same_as; { j[n] } -> same_as<iter_reference_t>; }; }
[edit] Concept contiguous_iterator
namespace std { template concept contiguous_iterator = random_access_iterator && derived_from</* ITER_CONCEPT */(I), contiguous_iterator_tag> && is_lvalue_reference_v<iter_reference_t> && same_as<iter_value_t, remove_cvref_t<iter_reference_t>> && requires(const I& i) { { to_address(i) } -> same_as<add_pointer_t<iter_reference_t>>; }; }
[edit] Concept indirectly_unary_invocable
namespace std { template<class F, class I> concept indirectly_unary_invocable = indirectly_readable && copy_constructible && invocable<F&, iter_value_t&> && invocable<F&, iter_reference_t> && common_reference_with< invoke_result_t<F&, iter_value_t&>, invoke_result_t<F&, iter_reference_t>>; }
[edit] Concept indirectly_regular_unary_invocable
namespace std { template<class F, class I> concept indirectly_regular_unary_invocable = indirectly_readable && copy_constructible && regular_invocable<F&, iter_value_t&> && regular_invocable<F&, iter_reference_t> && common_reference_with< invoke_result_t<F&, iter_value_t&>, invoke_result_t<F&, iter_reference_t>>; }
[edit] Concept indirect_unary_predicate
namespace std { template<class F, class I> concept indirect_unary_predicate = indirectly_readable && copy_constructible && predicate<F&, iter_value_t&> && predicate<F&, iter_reference_t>; }
[edit] Concept indirect_binary_predicate
namespace std { template<class F, class I1, class I2 = I1> concept indirect_binary_predicate = indirectly_readable && indirectly_readable && copy_constructible && predicate<F&, iter_value_t&, iter_value_t&> && predicate<F&, iter_value_t&, iter_reference_t> && predicate<F&, iter_reference_t, iter_value_t&> && predicate<F&, iter_reference_t, iter_reference_t>; }
[edit] Concept indirect_equivalence_relation
namespace std { template<class F, class I1, class I2 = I1> concept indirect_equivalence_relation = indirectly_readable && indirectly_readable && copy_constructible && equivalence_relation<F&, iter_value_t&, iter_value_t&> && equivalence_relation<F&, iter_value_t&, iter_reference_t> && equivalence_relation<F&, iter_reference_t, iter_value_t&> && equivalence_relation<F&, iter_reference_t, iter_reference_t>; }
[edit] Concept indirect_strict_weak_order
namespace std { template<class F, class I1, class I2 = I1> concept indirect_strict_weak_order = indirectly_readable && indirectly_readable && copy_constructible && strict_weak_order<F&, iter_value_t&, iter_value_t&> && strict_weak_order<F&, iter_value_t&, iter_reference_t> && strict_weak_order<F&, iter_reference_t, iter_value_t&> && strict_weak_order<F&, iter_reference_t, iter_reference_t>; }
[edit] Concept indirectly_movable
namespace std { template<class In, class Out> concept indirectly_movable = indirectly_readable && indirectly_writable<Out, iter_rvalue_reference_t>; }
[edit] Concept indirectly_movable_storable
namespace std { template<class In, class Out> concept indirectly_movable_storable = indirectly_movable<In, Out> && indirectly_writable<Out, iter_value_t> && movable<iter_value_t> && constructible_from<iter_value_t, iter_rvalue_reference_t> && assignable_from<iter_value_t&, iter_rvalue_reference_t>; }
[edit] Concept indirectly_copyable
namespace std { template<class In, class Out> concept indirectly_copyable = indirectly_readable && indirectly_writable<Out, iter_reference_t>; }
[edit] Concept indirectly_copyable_storable
namespace std { template<class In, class Out> concept indirectly_copyable_storable = indirectly_copyable<In, Out> && indirectly_writable<Out, iter_value_t&> && indirectly_writable<Out, const iter_value_t&> && indirectly_writable<Out, iter_value_t&&> && indirectly_writable<Out, const iter_value_t&&> && copyable<iter_value_t> && constructible_from<iter_value_t, iter_reference_t> && assignable_from<iter_value_t&, iter_reference_t>; }
[edit] Concept indirectly_swappable
[edit] Concept indirectly_comparable
namespace std { template<class I1, class I2, class R, class P1 = identity, class P2 = identity> concept indirectly_comparable = indirect_predicate<R, projected<I1, P1>, projected<I2, P2>>; }
[edit] Concept permutable
namespace std { template concept permutable = forward_iterator && indirectly_movable_storable<I, I> && indirectly_swappable<I, I>; }
[edit] Concept mergeable
namespace std { template<class I1, class I2, class Out, class R = ranges::less, class P1 = identity, class P2 = identity> concept mergeable = input_iterator && input_iterator && weakly_incrementable && indirectly_copyable<I1, Out> && indirectly_copyable<I2, Out> && indirect_strict_weak_order<R, projected<I1, P1>, projected<I2, P2>>; }
[edit] Concept sortable
namespace std { template<class I, class R = ranges::less, class P = identity> concept sortable = permutable && indirect_strict_weak_order<R, projected<I, P>>; }
[edit] Class template std::incrementable_traits
namespace std { template struct incrementable_traits { }; template requires is_object_v struct incrementable_traits<T*> { using difference_type = ptrdiff_t; }; template struct incrementable_traits : incrementable_traits { }; template requires requires { typename T::difference_type; } struct incrementable_traits { using difference_type = typename T::difference_type; }; template requires (!requires { typename T::difference_type; } && requires(const T& a, const T& b) { { a - b } -> integral; }) struct incrementable_traits { using difference_type = make_signed_t<decltype(declval() - declval())>; }; template using iter_difference_t = /* see description */; }
[edit] Class template std::indirectly_readable_traits
namespace std { template struct /cond_value_type/ { }; // exposition only template requires is_object_v struct /cond_value_type/ { using value_type = remove_cv_t; }; template struct indirectly_readable_traits { }; template struct indirectly_readable_traits<T*> : /cond_value_type/ { }; template requires is_array_v struct indirectly_readable_traits { using value_type = remove_cv_t<remove_extent_t>; }; template struct indirectly_readable_traits : indirectly_readable_traits { }; template requires requires { typename T::value_type; } struct indirectly_readable_traits : /cond_value_type/ { }; template requires requires { typename T::element_type; } struct indirectly_readable_traits : /cond_value_type/ { }; }
[edit] Class template std::projected
namespace std { template<class I, class Proj> struct /projected-impl/ { // exposition only struct /type/ { // exposition only using value_type = remove_cvref_t<indirect_result_t<Proj&, I>>; using difference_type = iter_difference_t; // present only if I // models weakly_incrementable indirect_result_t<Proj&, I> operator*() const; // not defined }; }; template<indirectly_readable I, indirectly_regular_unary_invocable Proj> using projected = /projected-impl/<I, Proj>::/type/; }
[edit] Class template std::iterator_traits
namespace std { template struct iterator_traits { using iterator_category = /* see description /; using value_type = / see description /; using difference_type = / see description /; using pointer = / see description /; using reference = / see description /; }; template requires is_object_v struct iterator_traits<T*> { using iterator_concept = contiguous_iterator_tag; using iterator_category = random_access_iterator_tag; using value_type = remove_cv_t; using difference_type = ptrdiff_t; using pointer = T; using reference = T&; }; }
[edit] Iterator tags
namespace std { struct input_iterator_tag { }; struct output_iterator_tag { }; struct forward_iterator_tag: public input_iterator_tag { }; struct bidirectional_iterator_tag: public forward_iterator_tag { }; struct random_access_iterator_tag: public bidirectional_iterator_tag { }; struct contiguous_iterator_tag: public random_access_iterator_tag { }; }
[edit] Class template std::reverse_iterator
namespace std { template class reverse_iterator { public: using iterator_type = Iter; using iterator_concept = /* see description /; using iterator_category = / see description /; using value_type = iter_value_t; using difference_type = iter_difference_t; using pointer = typename iterator_traits::pointer; using reference = iter_reference_t; constexpr reverse_iterator(); constexpr explicit reverse_iterator(Iter x); template constexpr reverse_iterator(const reverse_iterator& u); template constexpr reverse_iterator& operator=(const reverse_iterator& u); constexpr Iter base() const; constexpr reference operator() const; constexpr pointer operator->() const requires /* see description /; constexpr reverse_iterator& operator++(); constexpr reverse_iterator operator++(int); constexpr reverse_iterator& operator--(); constexpr reverse_iterator operator--(int); constexpr reverse_iterator operator+ (difference_type n) const; constexpr reverse_iterator& operator+=(difference_type n); constexpr reverse_iterator operator- (difference_type n) const; constexpr reverse_iterator& operator-=(difference_type n); constexpr / unspecified / operator[](difference_type n) const; friend constexpr iter_rvalue_reference_t iter_move(const reverse_iterator& i) noexcept(/ see description /); template<indirectly_swappable Iter2> friend constexpr void iter_swap(const reverse_iterator& x, const reverse_iterator& y) noexcept(/ see description */); protected: Iter current; }; }
[edit] Class template std::back_insert_iterator
namespace std { template class back_insert_iterator { protected: Container* container = nullptr; public: using iterator_category = output_iterator_tag; using value_type = void; using difference_type = ptrdiff_t; using pointer = void; using reference = void; using container_type = Container; constexpr back_insert_iterator() noexcept = default; constexpr explicit back_insert_iterator(Container& x); constexpr back_insert_iterator& operator=(const typename Container::value_type& value); constexpr back_insert_iterator& operator=(typename Container::value_type&& value); constexpr back_insert_iterator& operator*(); constexpr back_insert_iterator& operator++(); constexpr back_insert_iterator operator++(int); }; }
[edit] Class template std::front_insert_iterator
namespace std { template class front_insert_iterator { protected: Container* container = nullptr; public: using iterator_category = output_iterator_tag; using value_type = void; using difference_type = ptrdiff_t; using pointer = void; using reference = void; using container_type = Container; constexpr front_insert_iterator(Container& x) noexcept = default; constexpr explicit front_insert_iterator(Container& x); constexpr front_insert_iterator& operator=(const typename Container::value_type& value); constexpr front_insert_iterator& operator=(typename Container::value_type&& value); constexpr front_insert_iterator& operator*(); constexpr front_insert_iterator& operator++(); constexpr front_insert_iterator operator++(int); }; }
[edit] Class template std::insert_iterator
namespace std { template class insert_iterator { protected: Container* container = nullptr; ranges::iterator_t iter = ranges::iterator_t(); public: using iterator_category = output_iterator_tag; using value_type = void; using difference_type = ptrdiff_t; using pointer = void; using reference = void; using container_type = Container; insert_iterator() = default; constexpr insert_iterator(Container& x, ranges::iterator_t i); constexpr insert_iterator& operator=(const typename Container::value_type& value); constexpr insert_iterator& operator=(typename Container::value_type&& value); constexpr insert_iterator& operator*(); constexpr insert_iterator& operator++(); constexpr insert_iterator& operator++(int); }; }
[edit] Class template std::move_iterator
namespace std {
template
class move_iterator {
public:
using iterator_type = Iter;
using iterator_concept = /* see description /;
using iterator_category = / see description /;
using value_type = iter_value_t;
using difference_type = iter_difference_t;
using pointer = Iter;
using reference = iter_rvalue_reference_t;
constexpr move_iterator();
constexpr explicit move_iterator(Iter i);
template constexpr move_iterator(const move_iterator& u);
template constexpr move_iterator& operator=(const move_iterator& u);
constexpr iterator_type base() const &;
constexpr iterator_type base() &&;
constexpr reference operator() const;
constexpr pointer operator->() const;
constexpr move_iterator& operator++();
constexpr auto operator++(int);
constexpr move_iterator& operator--();
constexpr move_iterator operator--(int);
constexpr move_iterator operator+(difference_type n) const;
constexpr move_iterator& operator+=(difference_type n);
constexpr move_iterator operator-(difference_type n) const;
constexpr move_iterator& operator-=(difference_type n);
constexpr reference operator[](difference_type n) const;
template<sentinel_for S>
friend constexpr bool
operator==(const move_iterator& x, const move_sentinel& y);
template<sized_sentinel_for S>
friend constexpr iter_difference_t
operator-(const move_sentinel& x, const move_iterator& y);
template<sized_sentinel_for S>
friend constexpr iter_difference_t
operator-(const move_iterator& x, const move_sentinel& y);
friend constexpr iter_rvalue_reference_t
iter_move(const move_iterator& i)
noexcept(noexcept(ranges::iter_move(i.current)));
template<indirectly_swappable Iter2>
friend constexpr void
iter_swap(const move_iterator& x, const move_iterator& y)
noexcept(noexcept(ranges::iter_swap(x.current, y.current)));
private:
Iter current; // exposition only
};
}
[edit] Class template std::move_sentinel
namespace std { template class move_sentinel { public: constexpr move_sentinel(); constexpr explicit move_sentinel(S s); template requires convertible_to<const S2&, S> constexpr move_sentinel(const move_sentinel& s); template requires assignable_from<S&, const S2&> constexpr move_sentinel& operator=(const move_sentinel& s); constexpr S base() const; private: S last; // exposition only }; }
[edit] Class template std::common_iterator
namespace std { template<input_or_output_iterator I, sentinel_for S> requires (!same_as<I, S> && copyable) class common_iterator { public: constexpr common_iterator() = default; constexpr common_iterator(I i); constexpr common_iterator(S s); template<class I2, class S2> requires convertible_to<const I2&, I> && convertible_to<const S2&, S> constexpr common_iterator(const common_iterator<I2, S2>& x); template<class I2, class S2> requires convertible_to<const I2&, I> && convertible_to<const S2&, S> && assignable_from<I&, const I2&> && assignable_from<S&, const S2&> common_iterator& operator=(const common_iterator<I2, S2>& x); decltype(auto) operator*(); decltype(auto) operator*() const requires dereferenceable; decltype(auto) operator->() const requires /* see description /; common_iterator& operator++(); decltype(auto) operator++(int); template<class I2, sentinel_for S2> requires sentinel_for<S, I2> friend bool operator==( const common_iterator& x, const common_iterator<I2, S2>& y); template<class I2, sentinel_for S2> requires sentinel_for<S, I2> && equality_comparable_with<I, I2> friend bool operator==( const common_iterator& x, const common_iterator<I2, S2>& y); template<sized_sentinel_for I2, sized_sentinel_for S2> requires sized_sentinel_for<S, I2> friend iter_difference_t operator-( const common_iterator& x, const common_iterator<I2, S2>& y); friend constexpr decltype(auto) iter_move(const common_iterator& i) noexcept(noexcept(ranges::iter_move(declval<const I&>()))) requires input_iterator; template<indirectly_swappable I2, class S2> friend void iter_swap(const common_iterator& x, const common_iterator<I2, S2>& y) noexcept(noexcept(ranges::iter_swap(declval<const I&>(), declval<const I2&>()))); private: variant<I, S> v_; // exposition only }; template<class I, class S> struct incrementable_traits<common_iterator<I, S>> { using difference_type = iter_difference_t; }; template<input_iterator I, class S> struct iterator_traits<common_iterator<I, S>> { using iterator_concept = / see description /; using iterator_category = / see description /; using value_type = iter_value_t; using difference_type = iter_difference_t; using pointer = / see description */; using reference = iter_reference_t; }; }
[edit] Class std::default_sentinel_t
namespace std { struct default_sentinel_t { }; }
[edit] Class template std::counted_iterator
namespace std { template class counted_iterator { public: using iterator_type = I; constexpr counted_iterator() = default; constexpr counted_iterator(I x, iter_difference_t n); template requires convertible_to<const I2&, I> constexpr counted_iterator(const counted_iterator& x); template requires assignable_from<I&, const I2&> constexpr counted_iterator& operator=(const counted_iterator& x); constexpr I base() const & requires copy_constructible; constexpr I base() &&; constexpr iter_difference_t count() const noexcept; constexpr decltype(auto) operator*(); constexpr decltype(auto) operator*() const requires dereferenceable; constexpr auto operator->() const noexcept requires contiguous_iterator; constexpr counted_iterator& operator++(); decltype(auto) operator++(int); constexpr counted_iterator operator++(int) requires forward_iterator; constexpr counted_iterator& operator--() requires bidirectional_iterator; constexpr counted_iterator operator--(int) requires bidirectional_iterator; constexpr counted_iterator operator+(iter_difference_t n) const requires random_access_iterator; friend constexpr counted_iterator operator+( iter_difference_t n, const counted_iterator& x) requires random_access_iterator; constexpr counted_iterator& operator+=(iter_difference_t n) requires random_access_iterator; constexpr counted_iterator operator-(iter_difference_t n) const requires random_access_iterator; template<common_with I2> friend constexpr iter_difference_t operator-( const counted_iterator& x, const counted_iterator& y); friend constexpr iter_difference_t operator-( const counted_iterator& x, default_sentinel_t); friend constexpr iter_difference_t operator-( default_sentinel_t, const counted_iterator& y); constexpr counted_iterator& operator-=(iter_difference_t n) requires random_access_iterator; constexpr decltype(auto) operator[](iter_difference_t n) const requires random_access_iterator; template<common_with I2> friend constexpr bool operator==( const counted_iterator& x, const counted_iterator& y); friend constexpr bool operator==( const counted_iterator& x, default_sentinel_t); template<common_with I2> friend constexpr strong_ordering operator<=>( const counted_iterator& x, const counted_iterator& y); friend constexpr decltype(auto) iter_move(const counted_iterator& i) noexcept(noexcept(ranges::iter_move(i.current))) requires input_iterator; template<indirectly_swappable I2> friend constexpr void iter_swap(const counted_iterator& x, const counted_iterator& y) noexcept(noexcept(ranges::iter_swap(x.current, y.current))); private: I current = I(); // exposition only iter_difference_t length = 0; // exposition only }; template struct iterator_traits<counted_iterator> : iterator_traits { using pointer = void; }; }
[edit] Class std::unreachable_sentinel_t
namespace std { struct unreachable_sentinel_t { template friend constexpr bool operator==(unreachable_sentinel_t, const I&) noexcept { return false; } }; }
[edit] Class template std::istream_iterator
namespace std { template<class T, class CharT = char, class Traits = char_traits, class Distance = ptrdiff_t> class istream_iterator { public: using iterator_category = input_iterator_tag; using value_type = T; using difference_type = Distance; using pointer = const T*; using reference = const T&; using char_type = CharT; using traits_type = Traits; using istream_type = basic_istream<CharT, Traits>; constexpr istream_iterator(); constexpr istream_iterator(default_sentinel_t); istream_iterator(istream_type& s); istream_iterator(const istream_iterator& x) = default; ~istream_iterator() = default; istream_iterator& operator=(const istream_iterator&) = default; const T& operator*() const; const T* operator->() const; istream_iterator& operator++(); istream_iterator operator++(int); friend bool operator==(const istream_iterator& i, default_sentinel_t); private: basic_istream<CharT, Traits>* in_stream; // exposition only T value; // exposition only }; }
[edit] Class template std::ostream_iterator
namespace std { template<class T, class CharT = char, classTraits = char_traits> class ostream_iterator { public: using iterator_category = output_iterator_tag; using value_type = void; using difference_type = ptrdiff_t; using pointer = void; using reference = void; using char_type = CharT; using traits_type = Traits; using ostream_type = basic_ostream<CharT, Traits>; constexpr ostreambuf_iterator() noexcept = default; ostream_iterator(ostream_type& s); ostream_iterator(ostream_type& s, const CharT* delimiter); ostream_iterator(const ostream_iterator& x); ~ostream_iterator(); ostream_iterator& operator=(const ostream_iterator&) = default; ostream_iterator& operator=(const T& value); ostream_iterator& operator*(); ostream_iterator& operator++(); ostream_iterator& operator++(int); private: basic_ostream<CharT, Traits>* out_stream = nullptr; // exposition only const CharT* delim = nullptr; // exposition only }; }
[edit] Class template std::istreambuf_iterator
namespace std { template<class CharT, class Traits = char_traits> class istreambuf_iterator { public: using iterator_category = input_iterator_tag; using value_type = CharT; using difference_type = typename Traits::off_type; using pointer = /* unspecified /; using reference = CharT; using char_type = CharT; using traits_type = Traits; using int_type = typename Traits::int_type; using streambuf_type = basic_streambuf<CharT, Traits>; using istream_type = basic_istream<CharT, Traits>; class proxy; // exposition only constexpr istreambuf_iterator() noexcept; constexpr istreambuf_iterator(default_sentinel_t) noexcept; istreambuf_iterator(const istreambuf_iterator&) noexcept = default; ~istreambuf_iterator() = default; istreambuf_iterator(istream_type& s) noexcept; istreambuf_iterator(streambuf_type s) noexcept; istreambuf_iterator(const proxy& p) noexcept; istreambuf_iterator& operator=(const istreambuf_iterator&) noexcept = default; CharT operator*() const; istreambuf_iterator& operator++(); proxy operator++(int); bool equal(const istreambuf_iterator& b) const; friend bool operator==(const istreambuf_iterator& i, default_sentinel_t s); private: streambuf_type* sbuf_; // exposition only }; template<class CharT, class Traits> class istreambuf_iterator<CharT, Traits>::proxy { // exposition only CharT keep_; basic_streambuf<CharT, Traits>* sbuf_; proxy(CharT c, basic_streambuf<CharT, Traits>* sbuf) : keep_(c), sbuf_(sbuf) { } public: CharT operator*() { return keep_; } }; }
[edit] Class template std::ostreambuf_iterator
namespace std { template<class CharT, class Traits = char_traits> class ostreambuf_iterator { public: using iterator_category = output_iterator_tag; using value_type = void; using difference_type = ptrdiff_t; using pointer = void; using reference = void; using char_type = CharT; using traits_type = Traits; using streambuf_type = basic_streambuf<CharT, Traits>; using ostream_type = basic_ostream<CharT, Traits>; constexpr ostreambuf_iterator() noexcept = default; ostreambuf_iterator(ostream_type& s) noexcept; ostreambuf_iterator(streambuf_type* s) noexcept; ostreambuf_iterator& operator=(CharT c); ostreambuf_iterator& operator*(); ostreambuf_iterator& operator++(); ostreambuf_iterator& operator++(int); bool failed() const noexcept; private: streambuf_type* sbuf_ = nullptr; // exposition only }; }
[edit] Class template std::iterator
namespace std { template<class Category, class T, class Distance = ptrdiff_t, class Pointer = T*, class Reference = T&> struct iterator { typedef Category iterator_category; typedef T value_type; typedef Distance difference_type; typedef Pointer pointer; typedef Reference reference; }; }
[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 349 | C++98 | the exposition-only member delim ofstd::ostream_iterator had type const char* | corrected to const CharT* |