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

30 KiB

[ranges.syn]

25 Ranges library [ranges]

25.2 Header synopsis [ranges.syn]

🔗

// mostly freestanding#include // see [compare.syn]#include <initializer_list> // see [initializer.list.syn]#include // see [iterator.synopsis]namespace std::ranges {inline namespace unspecified {// [range.access], range accessinline constexpr unspecified begin = unspecified; inline constexpr unspecified end = unspecified; inline constexpr unspecified cbegin = unspecified; inline constexpr unspecified cend = unspecified; inline constexpr unspecified rbegin = unspecified; inline constexpr unspecified rend = unspecified; inline constexpr unspecified crbegin = unspecified; inline constexpr unspecified crend = unspecified; inline constexpr unspecified size = unspecified; inline constexpr unspecified reserve_hint = unspecified; inline constexpr unspecified ssize = unspecified; inline constexpr unspecified empty = unspecified; inline constexpr unspecified data = unspecified; inline constexpr unspecified cdata = unspecified; }// [range.range], rangestemplateconcept range = see below; templateconstexpr bool enable_borrowed_range = false; templateconcept borrowed_range = see below; templateusing iterator_t = decltype(ranges::begin(declval<T&>())); template<range R>using sentinel_t = decltype(ranges::end(declval<R&>())); template<range R>using const_iterator_t = decltype(ranges::cbegin(declval<R&>())); template<range R>using const_sentinel_t = decltype(ranges::cend(declval<R&>())); template<range R>using range_difference_t = iter_difference_t<iterator_t>; template<sized_range R>using range_size_t = decltype(ranges::size(declval<R&>())); template<range R>using range_value_t = iter_value_t<iterator_t>; template<range R>using range_reference_t = iter_reference_t<iterator_t>; template<range R>using range_const_reference_t = iter_const_reference_t<iterator_t>; template<range R>using range_rvalue_reference_t = iter_rvalue_reference_t<iterator_t>; template<range R>using range_common_reference_t = iter_common_reference_t<iterator_t>; // [range.sized], sized rangestemplateconstexpr bool disable_sized_range = false; templateconcept approximately_sized_range = see below; templateconcept sized_range = see below; // [range.view], viewstemplateconstexpr bool enable_view = see below; struct view_base {}; templateconcept view = see below; // [range.refinements], other range refinementstemplate<class R, class T>concept output_range = see below; templateconcept input_range = see below; templateconcept forward_range = see below; templateconcept bidirectional_range = see below; templateconcept random_access_range = see below; templateconcept contiguous_range = see below; templateconcept common_range = see below; templateconcept viewable_range = see below; templateconcept constant_range = see below; templateconcept sized-random-access-range = see below; // exposition only// [view.interface], class template view_interfacetemplaterequires is_class_v && same_as<D, remove_cv_t>class view_interface; // [range.subrange], sub-rangesenum class subrange_kind : bool { unsized, sized }; template<input_or_output_iterator I, sentinel_for S = I, subrange_kind K = see below>requires (K == subrange_kind::sized || sized_sentinel_for<S, I>)class subrange; template<class I, class S, subrange_kind K>constexpr bool enable_borrowed_range<subrange<I, S, K>> = true; template<size_t N, class I, class S, subrange_kind K>requires ((N == 0 && copyable) || N == 1)constexpr auto get(const subrange<I, S, K>& r); template<size_t N, class I, class S, subrange_kind K>requires (N < 2)constexpr auto get(subrange<I, S, K>&& r);}namespace std {using ranges::get;}namespace std::ranges {// [range.dangling], dangling iterator handlingstruct dangling; // [range.elementsof], class template elements_oftemplate<range R, class Allocator = allocator>struct elements_of; // hostedtemplate<range R>using borrowed_iterator_t = see below; template<range R>using borrowed_subrange_t = see below; // [range.utility.conv], range conversionstemplate<class C, input_range R, class... Args> requires (view)constexpr C to(R&& r, Args&&... args); template<template<class...> class C, input_range R, class... Args>constexpr auto to(R&& r, Args&&... args); template<class C, class... Args> requires (view)constexpr auto to(Args&&... args); template<template<class...> class C, class... Args>constexpr auto to(Args&&... args); // [range.empty], empty viewtemplaterequires is_object_vclass empty_view; templateconstexpr bool enable_borrowed_range<empty_view> = true; namespace views {templateconstexpr empty_view empty{}; }// [range.single], single viewtemplate<move_constructible T>requires is_object_vclass single_view; namespace views { inline constexpr unspecified single = unspecified; }template<bool Const, class T>using maybe-const = conditional_t<Const, const T, T>; // exposition only// [range.iota], iota viewtemplate<weakly_incrementable W, semiregular Bound = unreachable_sentinel_t>requires weakly-equality-comparable-with<W, Bound> && copyableclass iota_view; template<class W, class Bound>constexpr bool enable_borrowed_range<iota_view<W, Bound>> = true; namespace views {inline constexpr unspecified iota = unspecified; inline constexpr unspecified indices = unspecified; }// [range.repeat], repeat viewtemplate<move_constructible T, semiregular Bound = unreachable_sentinel_t>requires see belowclass repeat_view; namespace views { inline constexpr unspecified repeat = unspecified; }// [range.istream], istream viewtemplate<movable Val, class CharT, class Traits = char_traits>requires see belowclass basic_istream_view; // hostedtemplateusing istream_view = basic_istream_view<Val, char>; // hostedtemplateusing wistream_view = basic_istream_view<Val, wchar_t>; // hostednamespace views {template constexpr unspecified istream = unspecified; // hosted}// [range.adaptor.object], range adaptor objectstemplaterequires is_class_v && same_as<D, remove_cv_t>class range_adaptor_closure { }; // [range.all], all viewnamespace views {inline constexpr unspecified all = unspecified; template<viewable_range R>using all_t = decltype(all(declval())); }// [range.ref.view], ref viewtemplate<range R>requires is_object_vclass ref_view; templateconstexpr bool enable_borrowed_range<ref_view> = true; // [range.owning.view], owning viewtemplate<range R>requires see belowclass owning_view; templateconstexpr bool enable_borrowed_range<owning_view> = enable_borrowed_range; // [range.as.rvalue], as rvalue viewtemplate<view V>requires input_rangeclass as_rvalue_view; templateconstexpr bool enable_borrowed_range<as_rvalue_view> = enable_borrowed_range; namespace views { inline constexpr unspecified as_rvalue = unspecified; }// [range.filter], filter viewtemplate<input_range V, indirect_unary_predicate<iterator_t> Pred>requires view && is_object_vclass filter_view; namespace views { inline constexpr unspecified filter = unspecified; }// [range.transform], transform viewtemplate<input_range V, move_constructible F>requires view && is_object_v &&regular_invocable<F&, range_reference_t> &&can-reference<invoke_result_t<F&, range_reference_t>>class transform_view; namespace views { inline constexpr unspecified transform = unspecified; }// [range.take], take viewtemplate<view> class take_view; templateconstexpr bool enable_borrowed_range<take_view> = enable_borrowed_range; namespace views { inline constexpr unspecified take = unspecified; }// [range.take.while], take while viewtemplate<view V, class Pred>requires input_range && is_object_v &&indirect_unary_predicate<const Pred, iterator_t>class take_while_view; namespace views { inline constexpr unspecified take_while = unspecified; }// [range.drop], drop viewtemplate<view V>class drop_view; templateconstexpr bool enable_borrowed_range<drop_view> = enable_borrowed_range; namespace views { inline constexpr unspecified drop = unspecified; }// [range.drop.while], drop while viewtemplate<view V, class Pred>requires input_range && is_object_v &&indirect_unary_predicate<const Pred, iterator_t>class drop_while_view; template<class T, class Pred>constexpr bool enable_borrowed_range<drop_while_view<T, Pred>> = enable_borrowed_range; namespace views { inline constexpr unspecified drop_while = unspecified; }// [range.join], join viewtemplate<input_range V>requires view && input_range<range_reference_t>class join_view; namespace views { inline constexpr unspecified join = unspecified; }// [range.join.with], join with viewtemplate<input_range V, forward_range Pattern>requires see belowclass join_with_view; namespace views { inline constexpr unspecified join_with = unspecified; }// [range.lazy.split], lazy split viewtemplateconcept tiny-range = see below; // exposition onlytemplate<input_range V, forward_range Pattern>requires view && view &&indirectly_comparable<iterator_t, iterator_t, ranges::equal_to> &&(forward_range || tiny-range)class lazy_split_view; // [range.split], split viewtemplate<forward_range V, forward_range Pattern>requires view && view &&indirectly_comparable<iterator_t, iterator_t, ranges::equal_to>class split_view; namespace views {inline constexpr unspecified lazy_split = unspecified; inline constexpr unspecified split = unspecified; }// [range.concat], concat viewtemplate<input_range... Views>requires see belowclass concat_view; namespace views { inline constexpr unspecified concat = unspecified; }// [range.counted], counted viewnamespace views { inline constexpr unspecified counted = unspecified; }// [range.common], common viewtemplate<view V>requires (common_range && copyable<iterator_t>)class common_view; templateconstexpr bool enable_borrowed_range<common_view> = enable_borrowed_range; namespace views { inline constexpr unspecified common = unspecified; }// [range.reverse], reverse viewtemplate<view V>requires bidirectional_rangeclass reverse_view; templateconstexpr bool enable_borrowed_range<reverse_view> = enable_borrowed_range; namespace views { inline constexpr unspecified reverse = unspecified; }// [range.as.const], as const viewtemplate<input_range R>constexpr auto& possibly-const-range(R& r) noexcept { // exposition onlyif constexpr (input_range) {return const_cast<const R&>(r); } else {return r; }}template<view V>requires input_rangeclass as_const_view; templateconstexpr bool enable_borrowed_range<as_const_view> = enable_borrowed_range; namespace views { inline constexpr unspecified as_const = unspecified; }// [range.elements], elements viewtemplate<input_range V, size_t N>requires see belowclass elements_view; template<class T, size_t N>constexpr bool enable_borrowed_range<elements_view<T, N>> = enable_borrowed_range; templateusing keys_view = elements_view<R, 0>; templateusing values_view = elements_view<R, 1>; namespace views {template<size_t N>constexpr unspecified elements = unspecified; inline constexpr auto keys = elements<0>; inline constexpr auto values = elements<1>; }// [range.enumerate], enumerate viewtemplate<view V>requires see belowclass enumerate_view; templateconstexpr bool enable_borrowed_range<enumerate_view> = enable_borrowed_range; namespace views { inline constexpr unspecified enumerate = unspecified; }// [range.zip], zip viewtemplate<input_range... Views>requires (view && ...) && (sizeof...(Views) > 0)class zip_view; template<class... Views>constexpr bool enable_borrowed_range<zip_view<Views...>> =(enable_borrowed_range && ...); namespace views { inline constexpr unspecified zip = unspecified; }// [range.zip.transform], zip transform viewtemplate<move_constructible F, input_range... Views>requires (view && ...) && (sizeof...(Views) > 0) && is_object_v &&regular_invocable<F&, range_reference_t...> &&can-reference<invoke_result_t<F&, range_reference_t...>>class zip_transform_view; namespace views { inline constexpr unspecified zip_transform = unspecified; }// [range.adjacent], adjacent viewtemplate<forward_range V, size_t N>requires view && (N > 0)class adjacent_view; template<class V, size_t N>constexpr bool enable_borrowed_range<adjacent_view<V, N>> = enable_borrowed_range; namespace views {template<size_t N>constexpr unspecified adjacent = unspecified; inline constexpr auto pairwise = adjacent<2>; }// [range.adjacent.transform], adjacent transform viewtemplate<forward_range V, move_constructible F, size_t N>requires see belowclass adjacent_transform_view; namespace views {template<size_t N>constexpr unspecified adjacent_transform = unspecified; inline constexpr auto pairwise_transform = adjacent_transform<2>; }// [range.chunk], chunk viewtemplate<view V>requires input_rangeclass chunk_view; template<view V>requires forward_rangeclass chunk_view; templateconstexpr bool enable_borrowed_range<chunk_view> =forward_range && enable_borrowed_range; namespace views { inline constexpr unspecified chunk = unspecified; }// [range.slide], slide viewtemplate<forward_range V>requires viewclass slide_view; templateconstexpr bool enable_borrowed_range<slide_view> = enable_borrowed_range; namespace views { inline constexpr unspecified slide = unspecified; }// [range.chunk.by], chunk by viewtemplate<forward_range V, indirect_binary_predicate<iterator_t, iterator_t> Pred>requires view && is_object_vclass chunk_by_view; namespace views { inline constexpr unspecified chunk_by = unspecified; }// [range.stride], stride viewtemplate<input_range V>requires viewclass stride_view; templateconstexpr bool enable_borrowed_range<stride_view> = enable_borrowed_range; namespace views { inline constexpr unspecified stride = unspecified; }// [range.cartesian], cartesian product viewtemplate<input_range First, forward_range... Vs>requires (view && ... && view)class cartesian_product_view; namespace views { inline constexpr unspecified cartesian_product = unspecified; }// [range.cache.latest], cache latest viewtemplate<input_range V>requires viewclass cache_latest_view; namespace views { inline constexpr unspecified cache_latest = unspecified; }// [range.to.input], to input viewtemplate<input_range V>requires viewclass to_input_view; templateconstexpr bool enable_borrowed_range<to_input_view> = enable_borrowed_range; namespace views { inline constexpr unspecified to_input = unspecified; }}namespace std {namespace views = ranges::views; template struct tuple_size; template<size_t I, class T> struct tuple_element; template<class I, class S, ranges::subrange_kind K>struct tuple_size<ranges::subrange<I, S, K>>: integral_constant<size_t, 2> {}; template<class I, class S, ranges::subrange_kind K>struct tuple_element<0, ranges::subrange<I, S, K>> {using type = I; }; template<class I, class S, ranges::subrange_kind K>struct tuple_element<1, ranges::subrange<I, S, K>> {using type = S; }; template<class I, class S, ranges::subrange_kind K>struct tuple_element<0, const ranges::subrange<I, S, K>> {using type = I; }; template<class I, class S, ranges::subrange_kind K>struct tuple_element<1, const ranges::subrange<I, S, K>> {using type = S; }; struct from_range_t { explicit from_range_t() = default; }; inline constexpr from_range_t from_range{};}

1

#

Within this Clause, for an integer-like type X ([iterator.concept.winc]),make-unsigned-like-t denotesmake_unsigned_t if X is an integer type; otherwise, it denotes a corresponding unspecified unsigned-integer-like type of the same width as X.

For an expression x of type X,to-unsigned-like(x) isx explicitly converted tomake-unsigned-like-t.

2

#

Also within this Clause,make-signed-like-t for an integer-like type X denotes make_signed_t if X is an integer type; otherwise, it denotes a corresponding unspecified signed-integer-like type of the same width as X.