Files
2025-10-25 03:02:53 +03:00

32 KiB
Raw Permalink Blame History

[iterator.synopsis]

24 Iterators library [iterators]

24.2 Header synopsis [iterator.synopsis]

🔗

#include // see [compare.syn]#include // see [concepts.syn]namespace std {template using with-reference = T&; // exposition onlytemplate 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}; // [iterator.assoc.types], associated types// [incrementable.traits], incrementable traitstemplate struct incrementable_traits; // freestandingtemplateusing iter_difference_t = see below; // freestanding// [readable.traits], indirectly readable traitstemplate struct indirectly_readable_traits; // freestandingtemplateusing iter_value_t = see below; // freestanding// [iterator.traits], iterator traitstemplate struct iterator_traits; // freestandingtemplate requires is_object_v struct iterator_traits<T>; // freestandingtemplate<dereferenceable T>using iter_reference_t = decltype(declval<T&>()); // freestandingnamespace ranges {// [iterator.cust], customization point objectsinline namespace unspecified {// [iterator.cust.move], ranges::iter_moveinline constexpr unspecified iter_move = unspecified; // freestanding// [iterator.cust.swap], ranges::iter_swapinline constexpr unspecified iter_swap = unspecified; // freestanding}}template<dereferenceable T>requires requires(T& t) {{ ranges::iter_move(t) } -> can-reference; }using iter_rvalue_reference_t // freestanding= decltype(ranges::iter_move(declval<T&>())); // [iterator.concepts], iterator concepts// [iterator.concept.readable], concept indirectly_readabletemplateconcept indirectly_readable = see below; // freestanding// [indirectcallable.traits], indirect callable traitstemplate<indirectly_readable T>using indirect-value-t = see below; // exposition onlytemplate<indirectly_readable T>using iter_common_reference_t = // freestanding common_reference_t<iter_reference_t, indirect-value-t>; // [iterator.concept.writable], concept indirectly_writabletemplate<class Out, class T>concept indirectly_writable = see below; // freestanding// [iterator.concept.winc], concept weakly_incrementabletemplateconcept weakly_incrementable = see below; // freestanding// [iterator.concept.inc], concept incrementabletemplateconcept incrementable = see below; // freestanding// [iterator.concept.iterator], concept input_or_output_iteratortemplateconcept input_or_output_iterator = see below; // freestanding// [iterator.concept.sentinel], concept sentinel_fortemplate<class S, class I>concept sentinel_for = see below; // freestanding// [iterator.concept.sizedsentinel], concept sized_sentinel_fortemplate<class S, class I>constexpr bool disable_sized_sentinel_for = false; // freestandingtemplate<class S, class I>concept sized_sentinel_for = see below; // freestanding// [iterator.concept.input], concept input_iteratortemplateconcept input_iterator = see below; // freestanding// [iterator.concept.output], concept output_iteratortemplate<class I, class T>concept output_iterator = see below; // freestanding// [iterator.concept.forward], concept forward_iteratortemplateconcept forward_iterator = see below; // freestanding// [iterator.concept.bidir], concept bidirectional_iteratortemplateconcept bidirectional_iterator = see below; // freestanding// [iterator.concept.random.access], concept random_access_iteratortemplateconcept random_access_iterator = see below; // freestanding// [iterator.concept.contiguous], concept contiguous_iteratortemplateconcept contiguous_iterator = see below; // freestanding// [indirectcallable], indirect callable requirements// [indirectcallable.indirectinvocable], indirect callablestemplate<class F, class I>concept indirectly_unary_invocable = see below; // freestandingtemplate<class F, class I>concept indirectly_regular_unary_invocable = see below; // freestandingtemplate<class F, class I>concept indirect_unary_predicate = see below; // freestandingtemplate<class F, class I1, class I2>concept indirect_binary_predicate = see below; // freestandingtemplate<class F, class I1, class I2 = I1>concept indirect_equivalence_relation = see below; // freestandingtemplate<class F, class I1, class I2 = I1>concept indirect_strict_weak_order = see below; // freestandingtemplate<class F, class... Is>requires (indirectly_readable && ...) && invocable<F, iter_reference_t...>using indirect_result_t = invoke_result_t<F, iter_reference_t...>; // freestanding// [projected], projectedtemplate<indirectly_readable I, indirectly_regular_unary_invocable Proj>using projected = see below; // freestandingtemplate<indirectly_readable I, indirectly_regular_unary_invocable Proj>using projected_value_t = // freestanding remove_cvref_t<invoke_result_t<Proj&, iter_value_t&>>; // [alg.req], common algorithm requirements// [alg.req.ind.move], concept indirectly_movabletemplate<class In, class Out>concept indirectly_movable = see below; // freestandingtemplate<class In, class Out>concept indirectly_movable_storable = see below; // freestanding// [alg.req.ind.copy], concept indirectly_copyabletemplate<class In, class Out>concept indirectly_copyable = see below; // freestandingtemplate<class In, class Out>concept indirectly_copyable_storable = see below; // freestanding// [alg.req.ind.swap], concept indirectly_swappabletemplate<class I1, class I2 = I1>concept indirectly_swappable = see below; // freestanding// [alg.req.ind.cmp], concept indirectly_comparabletemplate<class I1, class I2, class R, class P1 = identity, class P2 = identity>concept indirectly_comparable = see below; // freestanding// [alg.req.permutable], concept permutabletemplateconcept permutable = see below; // freestanding// [alg.req.mergeable], concept mergeabletemplate<class I1, class I2, class Out, class R = ranges::less, class P1 = identity, class P2 = identity>concept mergeable = see below; // freestanding// [alg.req.sortable], concept sortabletemplate<class I, class R = ranges::less, class P = identity>concept sortable = see below; // freestanding// [iterator.primitives], primitives// [std.iterator.tags], iterator tagsstruct input_iterator_tag { }; // freestandingstruct output_iterator_tag { }; // freestandingstruct forward_iterator_tag: public input_iterator_tag { }; // freestandingstruct bidirectional_iterator_tag: public forward_iterator_tag { }; // freestandingstruct random_access_iterator_tag: public bidirectional_iterator_tag { }; // freestandingstruct contiguous_iterator_tag: public random_access_iterator_tag { }; // freestanding// [iterator.operations], iterator operationstemplate<class InputIterator, class Distance>constexpr void advance(InputIterator& i, Distance n); // freestandingtemplateconstexpr typename iterator_traits::difference_type distance(InputIterator first, InputIterator last); // freestandingtemplateconstexpr InputIterator next(InputIterator x, // freestandingtypename iterator_traits::difference_type n = 1); templateconstexpr BidirectionalIterator prev(BidirectionalIterator x, // freestandingtypename iterator_traits::difference_type n = 1); // [range.iter.ops], range iterator operationsnamespace ranges {// [range.iter.op.advance], ranges::advancetemplate<input_or_output_iterator I>constexpr void advance(I& i, iter_difference_t n); // freestandingtemplate<input_or_output_iterator I, sentinel_for S>constexpr void advance(I& i, S bound); // freestandingtemplate<input_or_output_iterator I, sentinel_for S>constexpr iter_difference_t advance(I& i, iter_difference_t n, // freestanding S bound); // [range.iter.op.distance], ranges::distancetemplate<class I, sentinel_for S>requires (sized_sentinel_for<S, I>)constexpr iter_difference_t distance(I first, S last); // freestandingtemplate<class I, sized_sentinel_for<decay_t> S>constexpr iter_difference_t<decay_t> distance(I&& first, S last); // freestandingtemplate<range R>constexpr range_difference_t distance(R&& r); // freestanding// [range.iter.op.next], ranges::nexttemplate<input_or_output_iterator I>constexpr I next(I x); // freestandingtemplate<input_or_output_iterator I>constexpr I next(I x, iter_difference_t n); // freestandingtemplate<input_or_output_iterator I, sentinel_for S>constexpr I next(I x, S bound); // freestandingtemplate<input_or_output_iterator I, sentinel_for S>constexpr I next(I x, iter_difference_t n, S bound); // freestanding// [range.iter.op.prev], ranges::prevtemplate<bidirectional_iterator I>constexpr I prev(I x); // freestandingtemplate<bidirectional_iterator I>constexpr I prev(I x, iter_difference_t n); // freestandingtemplate<bidirectional_iterator I>constexpr I prev(I x, iter_difference_t n, I bound); // freestanding}// [predef.iterators], predefined iterators and sentinels// [reverse.iterators], reverse iteratorstemplate class reverse_iterator; // freestandingtemplate<class Iterator1, class Iterator2>constexpr bool operator==( // freestandingconst reverse_iterator& x, const reverse_iterator& y); template<class Iterator1, class Iterator2>constexpr bool operator!=( // freestandingconst reverse_iterator& x, const reverse_iterator& y); template<class Iterator1, class Iterator2>constexpr bool operator<( // freestandingconst reverse_iterator& x, const reverse_iterator& y); template<class Iterator1, class Iterator2>constexpr bool operator>( // freestandingconst reverse_iterator& x, const reverse_iterator& y); template<class Iterator1, class Iterator2>constexpr bool operator<=( // freestandingconst reverse_iterator& x, const reverse_iterator& y); template<class Iterator1, class Iterator2>constexpr bool operator>=( // freestandingconst reverse_iterator& x, const reverse_iterator& y); template<class Iterator1, three_way_comparable_with Iterator2>constexpr compare_three_way_result_t<Iterator1, Iterator2>operator<=>(const reverse_iterator& x, // freestandingconst reverse_iterator& y); template<class Iterator1, class Iterator2>constexpr auto operator-( // freestandingconst reverse_iterator& x, const reverse_iterator& y) -> decltype(y.base() - x.base()); templateconstexpr reverse_iterator operator+( // freestanding iter_difference_t n, const reverse_iterator& x); templateconstexpr reverse_iterator make_reverse_iterator(Iterator i); // freestandingtemplate<class Iterator1, class Iterator2>requires (sized_sentinel_for<Iterator1, Iterator2>)constexpr bool disable_sized_sentinel_for<reverse_iterator, // freestanding reverse_iterator> = true; // [insert.iterators], insert iteratorstemplate class back_insert_iterator; // freestandingtemplateconstexpr back_insert_iterator back_inserter(Container& x); // freestandingtemplate class front_insert_iterator; // freestandingtemplateconstexpr front_insert_iterator front_inserter(Container& x); // freestandingtemplate class insert_iterator; // freestandingtemplateconstexpr insert_iterator inserter(Container& x, ranges::iterator_t i); // freestanding// [const.iterators], constant iterators and sentinels// [const.iterators.alias], alias templatestemplate<indirectly_readable I>using iter_const_reference_t = see below; // freestandingtemplateconcept constant-iterator = see below; // exposition onlytemplate<input_iterator I>using const_iterator = see below; // freestandingtemplate<semiregular S>using const_sentinel = see below; // freestanding// [const.iterators.iterator], class template basic_const_iteratortemplate<input_iterator Iterator>class basic_const_iterator; // freestandingtemplate<class T, common_with U>requires input_iterator<common_type_t<T, U>>struct common_type<basic_const_iterator, U> { // freestandingusing type = basic_const_iterator<common_type_t<T, U>>; }; template<class T, common_with U>requires input_iterator<common_type_t<T, U>>struct common_type<U, basic_const_iterator> { // freestandingusing type = basic_const_iterator<common_type_t<T, U>>; }; template<class T, common_with U>requires input_iterator<common_type_t<T, U>>struct common_type<basic_const_iterator, basic_const_iterator> { // freestandingusing type = basic_const_iterator<common_type_t<T, U>>; }; template<input_iterator I>constexpr const_iterator make_const_iterator(I it) { return it; } // freestandingtemplate<semiregular S>constexpr const_sentinel make_const_sentinel(S s) { return s; } // freestanding// [move.iterators], move iterators and sentinelstemplate class move_iterator; // freestandingtemplate<class Iterator1, class Iterator2>constexpr bool operator==( // freestandingconst move_iterator& x, const move_iterator& y); template<class Iterator1, class Iterator2>constexpr bool operator<( // freestandingconst move_iterator& x, const move_iterator& y); template<class Iterator1, class Iterator2>constexpr bool operator>( // freestandingconst move_iterator& x, const move_iterator& y); template<class Iterator1, class Iterator2>constexpr bool operator<=( // freestandingconst move_iterator& x, const move_iterator& y); template<class Iterator1, class Iterator2>constexpr bool operator>=( // freestandingconst move_iterator& x, const move_iterator& y); template<class Iterator1, three_way_comparable_with Iterator2>constexpr compare_three_way_result_t<Iterator1, Iterator2>operator<=>(const move_iterator& x, // freestandingconst move_iterator& y); template<class Iterator1, class Iterator2>constexpr auto operator-( // freestandingconst move_iterator& x, const move_iterator& y)-> decltype(x.base() - y.base()); templateconstexpr move_iteratoroperator+(iter_difference_t n, const move_iterator& x); // freestandingtemplateconstexpr move_iterator make_move_iterator(Iterator i); // freestandingtemplate<class Iterator1, class Iterator2>requires (sized_sentinel_for<Iterator1, Iterator2>)constexpr bool disable_sized_sentinel_for<move_iterator, // freestanding move_iterator> = true; template<semiregular S> class move_sentinel; // freestanding// [iterators.common], common iteratorstemplate<input_or_output_iterator I, sentinel_for S>requires (same_as<I, S> && copyable)class common_iterator; // freestandingtemplate<class I, class S>struct incrementable_traits<common_iterator<I, S>>; // freestandingtemplate<input_iterator I, class S>struct iterator_traits<common_iterator<I, S>>; // freestanding// [default.sentinel], default sentinelstruct default_sentinel_t; // freestandinginline constexpr default_sentinel_t default_sentinel{}; // freestanding// [iterators.counted], counted iteratorstemplate<input_or_output_iterator I> class counted_iterator; // freestandingtemplate<input_iterator I>requires see belowstruct iterator_traits<counted_iterator>; // freestanding// [unreachable.sentinel], unreachable sentinelstruct unreachable_sentinel_t; // freestandinginline constexpr unreachable_sentinel_t unreachable_sentinel{}; // freestanding// [stream.iterators], stream iteratorstemplate<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; // [iterator.range], range accesstemplate constexpr auto begin(C& c) -> decltype(c.begin()); // freestandingtemplate constexpr auto begin(const C& c) -> decltype(c.begin()); // freestandingtemplate constexpr auto end(C& c) -> decltype(c.end()); // freestandingtemplate constexpr auto end(const C& c) -> decltype(c.end()); // freestandingtemplate<class T, size_t N> constexpr T begin(T (&array)[N]) noexcept; // freestandingtemplate<class T, size_t N> constexpr T* end(T (&array)[N]) noexcept; // freestandingtemplate constexpr auto cbegin(const C& c) // freestandingnoexcept(noexcept(std::begin(c))) -> decltype(std::begin(c)); template constexpr auto cend(const C& c) // freestandingnoexcept(noexcept(std::end(c))) -> decltype(std::end(c)); template constexpr auto rbegin(C& c) -> decltype(c.rbegin()); // freestandingtemplate constexpr auto rbegin(const C& c) -> decltype(c.rbegin()); // freestandingtemplate constexpr auto rend(C& c) -> decltype(c.rend()); // freestandingtemplate constexpr auto rend(const C& c) -> decltype(c.rend()); // freestandingtemplate<class T, size_t N> constexpr reverse_iterator<T*> rbegin(T (&array)[N]) // freestandingtemplate<class T, size_t N> constexpr reverse_iterator<T*> rend(T (&array)[N]); // freestandingtemplate constexpr reverse_iterator<const E*> rbegin(initializer_list il); // freestandingtemplate constexpr reverse_iterator<const E*> rend(initializer_list il); // freestandingtemplate constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // freestandingtemplate constexpr auto crend(const C& c) -> decltype(std::rend(c)); // freestandingtemplate constexpr auto size(const C& c) -> decltype(c.size()); // freestandingtemplate<class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // freestandingtemplate constexpr auto ssize(const C& c)-> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // freestandingtemplate<class T, ptrdiff_t N> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // freestandingtemplate constexpr auto empty(const C& c) -> decltype(c.empty()); // freestandingtemplate<class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // freestandingtemplate constexpr bool empty(initializer_list il) noexcept; // freestandingtemplate constexpr auto data(C& c) -> decltype(c.data()); // freestandingtemplate constexpr auto data(const C& c) -> decltype(c.data()); // freestandingtemplate<class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // freestandingtemplate constexpr const E* data(initializer_list il) noexcept; // freestanding}