Namespaces
Variants
Views
Actions

Standard library header <ranges>

From cppreference.com
< cpp‎ | header
 
 
 

This header is part of the ranges library.

Contents

[edit] Namespace aliases

namespace std {

    namespace views = ranges::views;

}

The namespace alias std::views is provided as a shorthand for std::ranges::views.

Concepts

Range concepts
Defined in namespace std::ranges
specifies that a type is a range, that is, it provides a begin iterator and an end sentinel
(concept) [edit]
specifies that a type is a range and iterators obtained from an expression of it can be safely returned without danger of dangling
(concept) [edit]
specifies that a range knows its size in constant time
(concept) [edit]
specifies that a range is a view, that is, it has constant time copy/move/assignment
(concept) [edit]
specifies a range whose iterator type satisfies input_iterator
(concept) [edit]
specifies a range whose iterator type satisfies output_iterator
(concept) [edit]
specifies a range whose iterator type satisfies forward_iterator
(concept) [edit]
specifies a range whose iterator type satisfies bidirectional_iterator
(concept) [edit]
specifies a range whose iterator type satisfies random_access_iterator
(concept) [edit]
specifies a range whose iterator type satisfies contiguous_iterator
(concept) [edit]
specifies that a range has identical iterator and sentinel types
(concept) [edit]
specifies the requirements for a range to be safely convertible to a view
(concept) [edit]

Classes

Range primitives
Defined in namespace std::ranges
obtains associated types of a range
(alias template) [edit]
Views
Defined in namespace std::ranges
helper class template for defining views, using the curiously recurring template pattern
(class template) [edit]
combines an iterator-sentinel pair into a view
(class template) [edit]
Dangling iterator handling
Defined in namespace std::ranges
a placeholder type indicating that an iterator or a subrange should not be returned since it would be dangling
(class) [edit]
obtains iterator type or subrange type of a borrowed_range
(alias template) [edit]
Factories
Defined in namespace std::ranges
an empty view with no elements
(class template) (variable template) [edit]
a view that contains a single element of a specified value
(class template) (customization point object) [edit]
a view consisting of a sequence generated by repeatedly incrementing an initial value
(class template) (customization point object) [edit]
a view consisting of the elements obtained by successive application of operator>> on the associated input stream
(class template) [edit]
creates a subrange from an iterator and a count
(customization point object) [edit]
Adaptors
Defined in namespace std::ranges
a view that includes all elements of a range
(alias template) (range adaptor object) [edit]
a view of the elements of some other range
(class template) [edit]
a view that consists of the elements of a range that satisfies a predicate
(class template) (range adaptor object) [edit]
a view of a sequence that applies a transformation function to each element
(class template) (range adaptor object) [edit]
a view consisting of the first N elements of another view
(class template) (range adaptor object) [edit]
a view consisting of the initial elements of another view, until the first element on which a predicate returns false
(class template) (range adaptor object) [edit]
a view consisting of elements of another view, skipping the first N elements
(class template) (range adaptor object) [edit]
a view consisting of the elements of another view, skipping the initial subsequence of elements until the first element where the predicate returns false
(class template) (range adaptor object) [edit]
a view consisting of the sequence obtained from flattening a view of ranges
(class template) (range adaptor object) [edit]
a view over the subranges obtained from splitting another view using a delimiter
(class template) (range adaptor object) [edit]
converts a view into a common_range
(class template) (range adaptor object) [edit]
a view that iterates over the elements of another bidirectional view in reverse order
(class template) (range adaptor object) [edit]
takes a view consisting of tuple-like values and a number N and produces a view of N'th element of each tuple
(class template) (range adaptor object) [edit]
takes a view consisting of pair-like values and produces a view of the first elements of each pair
(class template) (range adaptor object) [edit]
takes a view consisting of pair-like values and produces a view of the second elements of each pair
(class template) (range adaptor object) [edit]

Customization point objects

Range access
Defined in namespace std::ranges
returns an iterator to the beginning of a range
(customization point object) [edit]
returns a sentinel indicating the end of a range
(customization point object) [edit]
returns an iterator to the beginning of a read-only range
(customization point object) [edit]
returns a sentinel indicating the end of a read-only range
(customization point object) [edit]
returns a reverse iterator to a range
(customization point object) [edit]
returns a reverse end iterator to a range
(customization point object) [edit]
returns a reverse iterator to a read-only range
(customization point object) [edit]
returns a reverse end iterator to a read-only range
(customization point object) [edit]
returns an unsigned integer equal to the size of a range
(customization point object) [edit]
returns a signed integer equal to the size of a range
(customization point object) [edit]
checks whether a range is empty
(customization point object) [edit]
obtains a pointer to the beginning of a contiguous range
(customization point object) [edit]
obtains a pointer to the beginning of a read-only contiguous range
(customization point object) [edit]

[edit] Synopsis

#include <compare>
#include <initializer_list>
#include <iterator>
 
namespace std::ranges {
  inline namespace /* unspecified */ {
    // range access
    inline 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 */ ssize   = /* unspecified */;
    inline constexpr /* unspecified */ empty   = /* unspecified */;
    inline constexpr /* unspecified */ data    = /* unspecified */;
    inline constexpr /* unspecified */ cdata   = /* unspecified */;
  }
 
  // ranges
  template<class T>
    concept range = /* see definition */;
 
  template<class T>
    inline constexpr bool enable_borrowed_range = false;
 
  template<class T>
    concept borrowed_range = /* see definition */;
 
  template<class T>
    using iterator_t = decltype(ranges::begin(declval<T&>()));
  template<range R>
    using sentinel_t = decltype(ranges::end(declval<R&>()));
  template<range R>
    using range_difference_t = iter_difference_t<iterator_t<R>>;
  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<R>>;
  template<range R>
    using range_reference_t = iter_reference_t<iterator_t<R>>;
  template<range R>
    using range_rvalue_reference_t = iter_rvalue_reference_t<iterator_t<R>>;
 
  // sized ranges
  template<class>
    inline constexpr bool disable_sized_range = false;
 
  template<class T>
    concept sized_range = /* see definition */;
 
  // views
  template<class T>
    inline constexpr bool enable_view = /* see definition */;
 
  struct view_base { };
 
  template<class T>
    concept view = /* see definition */;
 
  // other range refinements
  template<class R, class T>
    concept output_range = /* see definition */;
 
  template<class T>
    concept input_range = /* see definition */;
 
  template<class T>
    concept forward_range = /* see definition */;
 
  template<class T>
    concept bidirectional_range = /* see definition */;
 
  template<class T>
    concept random_access_range = /* see definition */;
 
  template<class T>
    concept contiguous_range = /* see definition */;
 
  template<class T>
    concept common_range = /* see definition */;
 
  template<class T>
    concept viewable_range = /* see definition */;
 
  // class template view_interface
  template<class D>
    requires is_class_v<D> && same_as<D, remove_cv_t<D>>
  class view_interface;
 
  // sub-ranges
  enum class subrange_kind : bool { unsized, sized };
 
  template<input_or_output_iterator I, sentinel_for<I> S = I,
           subrange_kind K = /* see definition */>
    requires (K == subrange_kind::sized || !sized_sentinel_for<S, I>)
  class subrange;
 
  template<input_or_output_iterator I, sentinel_for<I> S, subrange_kind K>
    inline constexpr bool enable_borrowed_range<subrange<I, S, K>> = true;
 
  // dangling iterator handling
  struct dangling;
 
  template<range R>
    using borrowed_iterator_t = conditional_t<borrowed_range<R>, iterator_t<R>, dangling>;
 
  template<range R>
    using borrowed_subrange_t =
      conditional_t<borrowed_range<R>, subrange<iterator_t<R>>, dangling>;
 
  // empty view
  template<class T>
    requires is_object_v<T>
  class empty_view;
 
  template<class T>
    inline constexpr bool enable_borrowed_range<empty_view<T>> = true;
 
  namespace views {
    template<class T>
      inline constexpr empty_view<T> empty{};
  }
 
  // single view
  template<copy_constructible T>
    requires is_object_v<T>
  class single_view;
 
  namespace views { inline constexpr /* unspecified */ single = /* unspecified */; }
 
  // iota view
  template<weakly_incrementable W, semiregular Bound = unreachable_sentinel_t>
    requires __WeaklyEqualityComparableWith<W, Bound>
  class iota_view;
 
  template<weakly_incrementable W, semiregular Bound>
    inline constexpr bool enable_borrowed_range<iota_view<W, Bound>> = true;
 
  namespace views { inline constexpr /* unspecified */ iota = /* unspecified */; }
 
  // istream view
  template<movable Val, class CharT, class Traits = char_traits<CharT>>
    requires /* see definition */
  class basic_istream_view;
  template<class Val, class CharT, class Traits>
    basic_istream_view<Val, CharT, Traits> istream_view(basic_istream<CharT, Traits>& s);
 
  // all view
  namespace views {
    inline constexpr /* unspecified */ all = /* unspecified */;
 
    template<viewable_range R>
      using all_t = decltype(all(declval<R>()));
  }
 
  template<range R>
    requires is_object_v<R>
  class ref_view;
 
  template<class T>
    inline constexpr bool enable_borrowed_range<ref_view<T>> = true;
 
  // filter view
  template<input_range V, indirect_unary_predicate<iterator_t<V>> Pred>
    requires view<V> && is_object_v<Pred>
  class filter_view;
 
  namespace views { inline constexpr /* unspecified */ filter = /* unspecified */; }
 
  // transform view
  template<input_range V, copy_constructible F>
    requires view<V> && is_object_v<F> &&
             regular_invocable<F&, range_reference_t<V>>
  class transform_view;
 
  namespace views { inline constexpr /* unspecified */ transform = /* unspecified */; }
 
  // take view
  template<view> class take_view;
 
  namespace views { inline constexpr /* unspecified */ take = /* unspecified */; }
 
  // take while view
  template<view V, class Pred>
    requires input_range<V> && is_object_v<Pred> &&
             indirect_unary_predicate<const Pred, iterator_t<V>>
    class take_while_view;
 
  namespace views { inline constexpr /* unspecified */ take_while = /* unspecified */; }
 
  // drop view
  template<view V>
    class drop_view;
 
  namespace views { inline constexpr /* unspecified */ drop = /* unspecified */; }
 
  // drop while view
  template<view V, class Pred>
    requires input_range<V> && is_object_v<Pred> &&
             indirect_unary_predicate<const Pred, iterator_t<V>>
    class drop_while_view;
 
  namespace views { inline constexpr /* unspecified */ drop_while = /* unspecified */; }
 
  // join view
  template<input_range V>
    requires view<V> && input_range<range_reference_t<V>> &&
             (is_reference_v<range_reference_t<V>> ||
              view<range_value_t<V>>)
  class join_view;
 
  namespace views { inline constexpr /* unspecified */ join = /* unspecified */; }
 
  // split view
  template<class R>
    concept __TinyRange = /* see definition */;  // exposition only
 
  template<input_range V, forward_range Pattern>
    requires view<V> && view<Pattern> &&
             indirectly_comparable<iterator_t<V>, iterator_t<Pattern>, ranges::equal_to> &&
             (forward_range<V> || __TinyRange<Pattern>)
  class split_view;
 
  namespace views { inline constexpr /* unspecified */ split = /* unspecified */; }
 
  // counted view
  namespace views { inline constexpr /* unspecified */ counted = /* unspecified */; }
 
  // common view
  template<view V>
    requires (!common_range<V> && copyable<iterator_t<V>>)
  class common_view;
 
  namespace views { inline constexpr /* unspecified */ common = /* unspecified */; }
 
  // reverse view
  template<view V>
    requires bidirectional_range<V>
  class reverse_view;
 
  namespace views { inline constexpr /* unspecified */ reverse = /* unspecified */; }
 
  // elements view
  template<input_range V, size_t N>
    requires /* see definition */;
  class elements_view;
 
  template<class R>
    using keys_view = elements_view<views::all_t<R>, 0>;
  template<class R>
    using values_view = elements_view<views::all_t<R>, 1>;
 
  namespace views {
    template<size_t N>
      inline constexpr /* unspecified */ elements = /* unspecified */ ;
    inline constexpr auto keys = elements<0>;
    inline constexpr auto values = elements<1>;
  }
}
 
namespace std {
  namespace views = ranges::views;
 
  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;
  };
}

[edit] Concept range

namespace std::ranges {
  template< class T >
    concept range = requires(T& t) {
      ranges::begin(t); // equality-preserving for forward iterators
      ranges::end(t);
  };
}

[edit] Concept sized_range

namespace std::ranges {
  template< class T >
    concept sized_range = range<T> &&
      requires(T& t) {
        ranges::size(t);
      };
}

[edit] Concept view

namespace std::ranges {
  template<class T>
    inline constexpr bool enable_view = derived_from<T, view_base>;
 
  template<class T>
    concept view = range<T>
                && movable<T>
                && default_initializable<T>
                && enable_view<T>;
}

[edit] Concept output_range

namespace std::ranges {
  template<class R, class T>
    concept output_range =
      range<R> && output_iterator<iterator_t<R>, T>;
}

[edit] Concept input_range

namespace std::ranges {
  template<class T>
    concept input_range =
      range<T> && input_iterator<iterator_t<T>>;
}

[edit] Concept forward_range

namespace std::ranges {
  template<class T>
    concept forward_range =
      input_range<T> && forward_iterator<iterator_t<T>>;
}

[edit] Concept bidirectional_range

namespace std::ranges {
  template<class T>
    concept bidirectional_range =
      forward_range<T> && bidirectional_iterator<iterator_t<T>>;
}

[edit] Concept random_access_range

namespace std::ranges {
  template<class T>
    concept random_access_range =
      bidirectional_range<T> && random_access_iterator<iterator_t<T>>;
}

[edit] Concept contiguous_range

namespace std::ranges {
  template<class T>
    concept contiguous_range =
      random_access_range<T> && contiguous_iterator<iterator_t<T>> &&
        requires(T& t) {
          { ranges::data(t) } -> same_as<add_pointer_t<range_reference_t<T>>>;
        };
}

[edit] Concept common_range

namespace std::ranges {
  template<class T>
    concept common_range =
      range<T> && same_as<iterator_t<T>, sentinel_t<T>>;
}

[edit] Concept viewable_range

namespace std::ranges {
  template<class T>
    concept viewable_range =
      range<T> && (borrowed_range<T> || view<remove_cvref_t<T>>);
}

[edit] Helper concepts

namespace std::ranges { // unspecified, for name lookup only
  template<class R>
    concept __SimpleView =  // exposition only
      view<R> && range<const R> &&
      same_as<iterator_t<R>, iterator_t<const R>> &&
      same_as<sentinel_t<R>, sentinel_t<const R>>;
 
  template<input_iterator I>
    concept __HasArrow =  // exposition only
      is_pointer_v<I> || requires(I i) { i.operator->(); };
 
  template<class T, class U>
    concept __NotSameAs =  // exposition only
      !same_as<remove_cvref_t<T>, remove_cvref_t<U>>;
 
  template<class I>
    concept __Decrementable =  // exposition only
      __Incrementable<I> && requires(I i) {
        { --i } -> same_as<I&>;
        { i-- } -> same_as<I>;
      };
 
  template<class I>
    concept __Advanceable =  // exposition only
      __Decrementable<I> && totally_ordered<I> &&
      requires(I i, const I j, const iter_difference_t<I> n) {
          { i += n } -> same_as<I&>;
          { i -= n } -> same_as<I&>;
        I { j +  n };
        I { n +  j };
        I { j -  n };
          { j -  j } -> convertible_to<iter_difference_t<I>>;
      };
}

Note: These names are only for exposition, they are not part of the interface.

[edit] Class template std::ranges::view_interface

namespace std::ranges {
  template<class D>
    requires is_class_v<D> && same_as<D, remove_cv_t<D>>
  class view_interface : public view_base {
  private:
    constexpr D& derived() noexcept {  // exposition only
      return static_cast<D&>(*this);
    }
    constexpr const D& derived() const noexcept {  // exposition only
      return static_cast<const D&>(*this);
    }
  public:
    constexpr bool empty() requires forward_range<D> {
      return ranges::begin(derived()) == ranges::end(derived());
    }
    constexpr bool empty() const requires forward_range<const D> {
      return ranges::begin(derived()) == ranges::end(derived());
    }
 
    constexpr explicit operator bool()
      requires requires { ranges::empty(derived()); } {
        return !ranges::empty(derived());
      }
    constexpr explicit operator bool() const
      requires requires { ranges::empty(derived()); } {
        return !ranges::empty(derived());
      }
 
    constexpr auto data() requires contiguous_iterator<iterator_t<D>> {
      return to_address(ranges::begin(derived()));
    }
    constexpr auto data() const
      requires range<const D> && contiguous_iterator<iterator_t<const D>> {
        return to_address(ranges::begin(derived()));
      }
 
    constexpr auto size() requires forward_range<D> &&
      sized_sentinel_for<sentinel_t<D>, iterator_t<D>> {
        return ranges::end(derived()) - ranges::begin(derived());
      }
    constexpr auto size() const requires forward_range<const D> &&
      sized_sentinel_for<sentinel_t<const D>, iterator_t<const D>> {
        return ranges::end(derived()) - ranges::begin(derived());
      }
 
    constexpr decltype(auto) front() requires forward_range<D>;
    constexpr decltype(auto) front() const requires forward_range<const D>;
 
    constexpr decltype(auto) back() requires bidirectional_range<D> && common_range<D>;
    constexpr decltype(auto) back() const
      requires bidirectional_range<const D> && common_range<const D>;
 
    template<random_access_range R = D>
      constexpr decltype(auto) operator[](range_difference_t<R> n) {
        return ranges::begin(derived())[n];
      }
    template<random_access_range R = const D>
      constexpr decltype(auto) operator[](range_difference_t<R> n) const {
        return ranges::begin(derived())[n];
      }
  };
}

[edit] Class template std::ranges::subrange

namespace std::ranges {
  template<class From, class To>
    concept __ConvertibleToNonSlicing =  // exposition only
      convertible_to<From, To> &&
      !(is_pointer_v<decay_t<From>> &&
        is_pointer_v<decay_t<To>> &&
        __NotSameAs<remove_pointer_t<decay_t<From>>, remove_pointer_t<decay_t<To>>>);
 
  template<class T>
    concept __PairLike =  // exposition only
      !is_reference_v<T> && requires(T t) {
        typename tuple_size<T>::type;  // ensures tuple_size<T> is complete
        requires derived_from<tuple_size<T>, integral_constant<size_t, 2>>;
        typename tuple_element_t<0, remove_const_t<T>>;
        typename tuple_element_t<1, remove_const_t<T>>;
        { get<0>(t) } -> convertible_to<const tuple_element_t<0, T>&>;
        { get<1>(t) } -> convertible_to<const tuple_element_t<1, T>&>;
      };
 
  template<class T, class U, class V>
    concept __PairLikeConvertibleFrom =  // exposition only
      !range<T> && __PairLike<T> &&
      constructible_from<T, U, V> &&
      __ConvertibleToNonSlicing<U, tuple_element_t<0, T>> &&
      convertible_to<V, tuple_element_t<1, T>>;
 
  template<class T>
    concept __IteratorSentinelPair =  // exposition only
      !range<T> && __PairLike<T> &&
      sentinel_for<tuple_element_t<1, T>, tuple_element_t<0, T>>;
 
  template<input_or_output_iterator I, sentinel_for<I> S = I, subrange_kind K =
      sized_sentinel_for<S, I> ? subrange_kind::sized : subrange_kind::unsized>
    requires (K == subrange_kind::sized || !sized_sentinel_for<S, I>)
  class subrange : public view_interface<subrange<I, S, K>> {
  private:
    static constexpr bool StoreSize =                     // exposition only
      K == subrange_kind::sized && !sized_sentinel_for<S, I>;
    I begin_ = I();                                       // exposition only
    S end_ = S();                                         // exposition only
    __MakeUnsignedLikeT<iter_difference_t<I>> size_ = 0;  // exposition only; present only
                                                          // when StoreSize is true
  public:
    subrange() = default;
 
    constexpr subrange(__ConvertibleToNonSlicing<I> auto i, S s) requires (!StoreSize);
 
    constexpr subrange(__ConvertibleToNonSlicing<I> auto i, S s,
                       __MakeUnsignedLikeT<iter_difference_t<I>> n)
      requires (K == subrange_kind::sized);
 
    template<__NotSameAs<subrange> R>
      requires borrowed_range<R> &&
               __ConvertibleToNonSlicing<iterator_t<R>, I> &&
               convertible_to<sentinel_t<R>, S>
    constexpr subrange(R&& r) requires (!StoreSize || sized_range<R>);
 
    template<borrowed_range R>
      requires __ConvertibleToNonSlicing<iterator_t<R>, I> &&
               convertible_to<sentinel_t<R>, S>
    constexpr subrange(R&& r, __MakeUnsignedLikeT<iter_difference_t<I>> n)
      requires (K == subrange_kind::sized)
        : subrange{ranges::begin(r), ranges::end(r), n}
    {}
 
    template<__NotSameAs<subrange> PairLike>
      requires __PairLikeConvertibleFrom<PairLike, const I&, const S&>
    constexpr operator PairLike() const;
 
    constexpr I begin() const requires copyable<I>;
    [[nodiscard]] constexpr I begin() requires (!copyable<I>);
    constexpr S end() const;
 
    constexpr bool empty() const;
    constexpr __MakeUnsignedLikeT<iter_difference_t<I>> size() const
      requires (K == subrange_kind::sized);
 
    [[nodiscard]] constexpr subrange next(iter_difference_t<I> n = 1) const &
      requires forward_iterator<I>;
    [[nodiscard]] constexpr subrange next(iter_difference_t<I> n = 1) &&;
    [[nodiscard]] constexpr subrange prev(iter_difference_t<I> n = 1) const
      requires bidirectional_iterator<I>;
    constexpr subrange& advance(iter_difference_t<I> n);
  };
 
  template<input_or_output_iterator I, sentinel_for<I> S>
    subrange(I, S) -> subrange<I, S>;
 
  template<input_or_output_iterator I, sentinel_for<I> S>
    subrange(I, S, __MakeUnsignedLikeT<iter_difference_t<I>>) ->
      subrange<I, S, subrange_kind::sized>;
 
  template<__IteratorSentinelPair P>
    subrange(P) -> subrange<tuple_element_t<0, P>, tuple_element_t<1, P>>;
 
  template<__IteratorSentinelPair P>
    subrange(P, __MakeUnsignedLikeT<iter_difference_t<tuple_element_t<0, P>>>) ->
      subrange<tuple_element_t<0, P>, tuple_element_t<1, P>, subrange_kind::sized>;
 
  template<borrowed_range R>
    subrange(R&&) ->
      subrange<iterator_t<R>, sentinel_t<R>,
               (sized_range<R> || sized_sentinel_for<sentinel_t<R>, iterator_t<R>>)
                 ? subrange_kind::sized : subrange_kind::unsized>;
 
  template<borrowed_range R>
    subrange(R&&, __MakeUnsignedLikeT<range_difference_t<R>>) ->
      subrange<iterator_t<R>, sentinel_t<R>, subrange_kind::sized>;
 
  template<size_t N, class I, class S, subrange_kind K>
    requires (N < 2)
    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;
}

[edit] Class std::ranges::dangling

namespace std::ranges {
  struct dangling {
    constexpr dangling() noexcept = default;
    template<class... Args>
      constexpr dangling(Args&&...) noexcept { }
  };
}

[edit] Class template std::ranges::empty_view

namespace std::ranges {
  template<class T>
    requires is_object_v<T>
  class empty_view : public view_interface<empty_view<T>> {
  public:
    static constexpr T* begin() noexcept { return nullptr; }
    static constexpr T* end() noexcept { return nullptr; }
    static constexpr T* data() noexcept { return nullptr; }
    static constexpr size_t size() noexcept { return 0; }
    static constexpr bool empty() noexcept { return true; }
  };
}

[edit] Class template std::ranges::single_view

namespace std::ranges {
  template<copy_constructible T>
    requires is_object_v<T>
  class single_view : public view_interface<single_view<T>> {
  private:
    __SemiregularBox<T> value_;  // exposition only
  public:
    single_view() = default;
    constexpr explicit single_view(const T& t);
    constexpr explicit single_view(T&& t);
    template<class... Args>
      requires constructible_from<T, Args...>
    constexpr single_view(in_place_t, Args&&... args);
 
    constexpr T* begin() noexcept;
    constexpr const T* begin() const noexcept;
    constexpr T* end() noexcept;
    constexpr const T* end() const noexcept;
    static constexpr size_t size() noexcept;
    constexpr T* data() noexcept;
    constexpr const T* data() const noexcept;
  };
}

[edit] Class template std::ranges::iota_view

namespace std::ranges {
  template<class I>
    concept __Decrementable =  // exposition only
      /* see definition */;
  template<class I>
    concept __Advanceable =  // exposition only
      /* see definition */;
 
  template<weakly_incrementable W, semiregular Bound = unreachable_sentinel_t>
    requires __WeaklyEqualityComparableWith<W, Bound> && semiregular<W>
  class iota_view : public view_interface<iota_view<W, Bound>> {
  private:
    // class iota_view​::​iterator
    struct iterator;         // exposition only
    // class iota_view​::​sentinel
    struct sentinel;         // exposition only
    W value_ = W();          // exposition only
    Bound bound_ = Bound();  // exposition only
  public:
    iota_view() = default;
    constexpr explicit iota_view(W value);
    constexpr iota_view(type_identity_t<W> value,
                        type_identity_t<Bound> bound);
    constexpr iota_view(iterator first, sentinel last) : iota_view(*first, last.bound_) {}
 
    constexpr iterator begin() const;
    constexpr auto end() const;
    constexpr iterator end() const requires same_as<W, Bound>;
 
    constexpr auto size() const requires /* see definition */;
  };
 
  template<class W, class Bound>
    requires (!__IsIntegerLike<W> || !__IsIntegerLike<Bound> ||
              (__IsSignedIntegerLike<W> == __IsSignedIntegerLike<Bound>))
    iota_view(W, Bound) -> iota_view<W, Bound>;
}

[edit] Class std::ranges::iota_view::iterator

namespace std::ranges {
  template<weakly_incrementable W, semiregular Bound>
    requires __WeaklyEqualityComparableWith<W, Bound>
  struct iota_view<W, Bound>::iterator {
  private:
    W value_ = W();  // exposition only
  public:
    using iterator_concept = /* see definition */;
    using iterator_category = input_iterator_tag;
    using value_type = W;
    using difference_type = /* __iota_difference_t<W> */;
 
    iterator() = default;
    constexpr explicit iterator(W value);
 
    constexpr W operator*() const noexcept(is_nothrow_copy_constructible_v<W>);
 
    constexpr iterator& operator++();
    constexpr void operator++(int);
    constexpr iterator operator++(int) requires __Incrementable<W>;
 
    constexpr iterator& operator--() requires __Decrementable<W>;
    constexpr iterator operator--(int) requires __Decrementable<W>;
 
    constexpr iterator& operator+=(difference_type n)
      requires __Advanceable<W>;
    constexpr iterator& operator-=(difference_type n)
      requires __Advanceable<W>;
    constexpr W operator[](difference_type n) const
      requires __Advanceable<W>;
 
    friend constexpr bool operator==(const iterator& x, const iterator& y)
      requires equality_comparable<W>;
 
    friend constexpr bool operator<(const iterator& x, const iterator& y)
      requires totally_ordered<W>;
    friend constexpr bool operator>(const iterator& x, const iterator& y)
      requires totally_ordered<W>;
    friend constexpr bool operator<=(const iterator& x, const iterator& y)
      requires totally_ordered<W>;
    friend constexpr bool operator>=(const iterator& x, const iterator& y)
      requires totally_ordered<W>;
    friend constexpr auto operator<=>(const iterator& x, const iterator& y)
      requires totally_ordered<W> && three_way_comparable<W>;
 
    friend constexpr iterator operator+(iterator i, difference_type n)
      requires __Advanceable<W>;
    friend constexpr iterator operator+(difference_type n, iterator i)
      requires __Advanceable<W>;
 
    friend constexpr iterator operator-(iterator i, difference_type n)
      requires __Advanceable<W>;
    friend constexpr difference_type operator-(const iterator& x, const iterator& y)
      requires __Advanceable<W>;
  };
}

[edit] Class std::ranges::iota_view::sentinel

namespace std::ranges {
  template<weakly_incrementable W, semiregular Bound>
    requires __WeaklyEqualityComparableWith<W, Bound>
  struct iota_view<W, Bound>::sentinel {
  private:
    Bound bound_ = Bound();  // exposition only
  public:
    sentinel() = default;
    constexpr explicit sentinel(Bound bound);
 
    friend constexpr bool operator==(const iterator& x, const sentinel& y);
 
    friend constexpr iter_difference_t<W> operator-(const iterator& x, const sentinel& y)
      requires sized_sentinel_for<Bound, W>;
    friend constexpr iter_difference_t<W> operator-(const sentinel& x, const iterator& y)
      requires sized_sentinel_for<Bound, W>;
  };
}

[edit] Class template std::ranges::basic_istream_view

namespace std::ranges {
  template<class Val, class CharT, class Traits>
    concept __StreamExtractable =  // exposition only
      requires(basic_istream<CharT, Traits>& is, Val& t) {
         is >> t;
      };
 
  template<movable Val, class CharT, class Traits>
    requires default_initializable<Val> &&
             __StreamExtractable<Val, CharT, Traits>
  class basic_istream_view
        : public view_interface<basic_istream_view<Val, CharT, Traits>> {
  public:
    basic_istream_view() = default;
    constexpr explicit basic_istream_view(basic_istream<CharT, Traits>& stream);
 
    constexpr auto begin()
    {
      if (stream_) {
        *stream_ >> object_;
      }
      return iterator{*this};
    }
 
    constexpr default_sentinel_t end() const noexcept;
 
  private:
    struct iterator;                                  // exposition only
    basic_istream<CharT, Traits>* stream_ = nullptr;  // exposition only
    Val object_ = Val();                              // exposition only
  };
}

[edit] Class template std::ranges::basic_istream_view​::​iterator

namespace std::ranges {
  template<movable Val, class CharT, class Traits>
    requires default_initializable<Val> && __StreamExtractable<Val, CharT, Traits>
  class basic_istream_view<Val, CharT, Traits>::iterator {  // exposition only
  public:
    using iterator_concept = input_iterator_tag;
    using difference_type = ptrdiff_t;
    using value_type = Val;
 
    iterator() = default;
    constexpr explicit iterator(basic_istream_view& parent) noexcept;
 
    iterator(const iterator&) = delete;
    iterator(iterator&&) = default;
 
    iterator& operator=(const iterator&) = delete;
    iterator& operator=(iterator&&) = default;
 
    iterator& operator++();
    void operator++(int);
 
    Val& operator*() const;
 
    friend bool operator==(const iterator& x, default_sentinel_t);
 
  private:
    basic_istream_view* parent_ = nullptr;  // exposition only
  };
}

[edit] Class template std::ranges::ref_view

namespace std::ranges {
  template<range R>
    requires is_object_v<R>
  class ref_view : public view_interface<ref_view<R>> {
  private:
    R* r_ = nullptr;  // exposition only
  public:
    constexpr ref_view() noexcept = default;
 
    template<__NotSameAs<ref_view> T>
      requires /* see definition */
    constexpr ref_view(T&& t);
 
    constexpr R& base() const { return *r_; }
 
    constexpr iterator_t<R> begin() const { return ranges::begin(*r_); }
    constexpr sentinel_t<R> end() const { return ranges::end(*r_); }
 
    constexpr bool empty() const
      requires requires { ranges::empty(*r_); }
    { return ranges::empty(*r_); }
 
    constexpr auto size() const requires sized_range<R>
    { return ranges::size(*r_); }
 
    constexpr auto data() const requires contiguous_range<R>
    { return ranges::data(*r_); }
  };
  template<class R>
    ref_view(R&) -> ref_view<R>;
}

[edit] Class template std::ranges::filter_view

namespace std::ranges {
  template<input_range V, indirect_unary_predicate<iterator_t<V>> Pred>
    requires view<V> && is_object_v<Pred>
  class filter_view : public view_interface<filter_view<V, Pred>> {
  private:
    V base_ = V();                 // exposition only
    __SemiregularBox<Pred> pred_;  // exposition only
 
    // class filter_view​::​iterator
    class iterator;                // exposition only
    // class filter_view​::​sentinel
    class sentinel;                // exposition only
 
  public:
    filter_view() = default;
    constexpr filter_view(V base, Pred pred);
 
    constexpr V base() const& requires copy_constructible<V> { return base_; }
    constexpr V base() && { return std::move(base_); }
 
    constexpr const Pred& pred() const;
 
    constexpr iterator begin();
    constexpr auto end() {
      if constexpr (common_range<V>)
        return iterator{*this, ranges::end(base_)};
      else
        return sentinel{*this};
    }
  };
 
  template<class R, class Pred>
    filter_view(R&&, Pred) -> filter_view<views::all_t<R>, Pred>;
}

[edit] Class std::ranges::filter_view::iterator

namespace std::ranges {
  template<input_range V, indirect_unary_predicate<iterator_t<V>> Pred>
    requires view<V> && is_object_v<Pred>
  class filter_view<V, Pred>::iterator {
  private:
    iterator_t<V> current_ = iterator_t<V>();  // exposition only
    filter_view* parent_ = nullptr;            // exposition only
  public:
    using iterator_concept  = /* see definition */;
    using iterator_category = /* see definition */;
    using value_type        = range_value_t<V>;
    using difference_type   = range_difference_t<V>;
 
    iterator() = default;
    constexpr iterator(filter_view& parent, iterator_t<V> current);
 
    constexpr iterator_t<V> base() const &
      requires copyable<iterator_t<V>>;
    constexpr iterator_t<V> base() &&;
    constexpr range_reference_t<V> operator*() const;
    constexpr iterator_t<V> operator->() const
      requires __HasArrow<iterator_t<V>> && copyable<iterator_t<V>>;
 
    constexpr iterator& operator++();
    constexpr void operator++(int);
    constexpr iterator operator++(int) requires forward_range<V>;
 
    constexpr iterator& operator--() requires bidirectional_range<V>;
    constexpr iterator operator--(int) requires bidirectional_range<V>;
 
    friend constexpr bool operator==(const iterator& x, const iterator& y)
      requires equality_comparable<iterator_t<V>>;
 
    friend constexpr range_rvalue_reference_t<V> 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<iterator_t<V>>;
  };
}

[edit] Class std::ranges::filter_view::sentinel

namespace std::ranges {
  template<input_range V, indirect_unary_predicate<iterator_t<V>> Pred>
    requires view<V> && is_object_v<Pred>
  class filter_view<V, Pred>::sentinel {
  private:
    sentinel_t<V> end_ = sentinel_t<V>();  // exposition only
  public:
    sentinel() = default;
    constexpr explicit sentinel(filter_view& parent);
 
    constexpr sentinel_t<V> base() const;
 
    friend constexpr bool operator==(const iterator& x, const sentinel& y);
  };
}

[edit] Class template std::ranges::transform_view

namespace std::ranges {
  template<input_range V, copy_constructible F>
    requires view<V> && is_object_v<F> &&
             regular_invocable<F&, range_reference_t<V>> &&
             __CanReference<invoke_result_t<F&, range_reference_t<V>>>
  class transform_view : public view_interface<transform_view<V, F>> {
  private:
    // class template transform_view​::​iterator
    template<bool> struct iterator;  // exposition only
    // class template transform_view​::​sentinel
    template<bool> struct sentinel;  // exposition only
 
    V base_ = V();                   // exposition only
    __SemiregularBox<F> fun_;        // exposition only
 
  public:
    transform_view() = default;
    constexpr transform_view(V base, F fun);
 
    constexpr V base() const& requires copy_constructible<V> { return base_; }
    constexpr V base() && { return std::move(base_); }
 
    constexpr iterator<false> begin();
    constexpr iterator<true> begin() const
      requires range<const V> &&
               regular_invocable<const F&, range_reference_t<const V>>;
 
    constexpr sentinel<false> end();
    constexpr iterator<false> end() requires common_range<V>;
    constexpr sentinel<true> end() const
      requires range<const V> &&
               regular_invocable<const F&, range_reference_t<const V>>;
    constexpr iterator<true> end() const
      requires common_range<const V> &&
               regular_invocable<const F&, range_reference_t<const V>>;
 
    constexpr auto size() requires sized_range<V> { return ranges::size(base_); }
    constexpr auto size() const requires sized_range<const V>
    { return ranges::size(base_); }
  };
 
  template<class R, class F>
    transform_view(R&&, F) -> transform_view<views::all_t<R>, F>;
}

[edit] Class template std::ranges::transform_view::iterator

namespace std::ranges {
  template<input_range V, copy_constructible F>
    requires view<V> && is_object_v<F> &&
             regular_invocable<F&, range_reference_t<V>> &&
             __CanReference<invoke_result_t<F&, range_reference_t<V>>>
  template<bool Const>
  class transform_view<V, F>::iterator {
  private:
    using Parent =               // exposition only
      conditional_t<Const, const transform_view, transform_view>;
    using Base   =               // exposition only
      conditional_t<Const, const V, V>;
    iterator_t<Base> current_ =  // exposition only
      iterator_t<Base>();
    Parent* parent_ = nullptr;   // exposition only
  public:
    using iterator_concept  = /* see definition */;
    using iterator_category = /* see definition */;
    using value_type        =
      remove_cvref_t<invoke_result_t<F&, range_reference_t<Base>>>;
    using difference_type   = range_difference_t<Base>;
 
    iterator() = default;
    constexpr iterator(Parent& parent, iterator_t<Base> current);
    constexpr iterator(iterator<!Const> i)
      requires Const && convertible_to<iterator_t<V>, iterator_t<Base>>;
 
    constexpr iterator_t<Base> base() const &
      requires copyable<iterator_t<Base>>;
    constexpr iterator_t<Base> base() &&;
    constexpr decltype(auto) operator*() const
    { return invoke(*parent_->fun_, *current_); }
 
    constexpr iterator& operator++();
    constexpr void operator++(int);
    constexpr iterator operator++(int) requires forward_range<Base>;
 
    constexpr iterator& operator--() requires bidirectional_range<Base>;
    constexpr iterator operator--(int) requires bidirectional_range<Base>;
 
    constexpr iterator& operator+=(difference_type n)
      requires random_access_range<Base>;
    constexpr iterator& operator-=(difference_type n)
      requires random_access_range<Base>;
    constexpr decltype(auto) operator[](difference_type n) const
      requires random_access_range<Base>
    { return invoke(*parent_->fun_, current_[n]); }
 
    friend constexpr bool operator==(const iterator& x, const iterator& y)
      requires equality_comparable<iterator_t<Base>>;
 
    friend constexpr bool operator<(const iterator& x, const iterator& y)
      requires random_access_range<Base>;
    friend constexpr bool operator>(const iterator& x, const iterator& y)
      requires random_access_range<Base>;
    friend constexpr bool operator<=(const iterator& x, const iterator& y)
      requires random_access_range<Base>;
    friend constexpr bool operator>=(const iterator& x, const iterator& y)
      requires random_access_range<Base>;
    friend constexpr auto operator<=>(const iterator& x, const iterator& y)
      requires random_access_range<Base> && three_way_comparable<iterator_t<Base>>;
 
    friend constexpr iterator operator+(iterator i, difference_type n)
      requires random_access_range<Base>;
    friend constexpr iterator operator+(difference_type n, iterator i)
      requires random_access_range<Base>;
 
    friend constexpr iterator operator-(iterator i, difference_type n)
      requires random_access_range<Base>;
    friend constexpr difference_type operator-(const iterator& x, const iterator& y)
      requires random_access_range<Base>;
 
    friend constexpr decltype(auto) iter_move(const iterator& i)
      noexcept(noexcept(invoke(*i.parent_->fun_, *i.current_)))
    {
      if constexpr (is_lvalue_reference_v<decltype(*i)>)
        return std::move(*i);
      else
        return *i;
    }
 
    friend constexpr void iter_swap(const iterator& x, const iterator& y)
      noexcept(noexcept(ranges::iter_swap(x.current_, y.current_)))
      requires indirectly_swappable<iterator_t<Base>>;
  };
}

[edit] Class template std::ranges::transform_view::sentinel

namespace std::ranges {
  template<input_range V, copy_constructible F>
    requires view<V> && is_object_v<F> &&
             regular_invocable<F&, range_reference_t<V>> &&
             __CanReference<invoke_result_t<F&, range_reference_t<V>>>
  template<bool Const>
  class transform_view<V, F>::sentinel {
  private:
    using Parent =                                  // exposition only
      conditional_t<Const, const transform_view, transform_view>;
    using Base = conditional_t<Const, const V, V>;  // exposition only
    sentinel_t<Base> end_ = sentinel_t<Base>();     // exposition only
  public:
    sentinel() = default;
    constexpr explicit sentinel(sentinel_t<Base> end);
    constexpr sentinel(sentinel<!Const> i)
      requires Const && convertible_to<sentinel_t<V>, sentinel_t<Base>>;
 
    constexpr sentinel_t<Base> base() const;
 
    friend constexpr bool operator==(const iterator<Const>& x, const sentinel& y);
 
    friend constexpr range_difference_t<Base>
      operator-(const iterator<Const>& x, const sentinel& y)
        requires sized_sentinel_for<sentinel_t<Base>, iterator_t<Base>>;
    friend constexpr range_difference_t<Base>
      operator-(const sentinel& y, const iterator<Const>& x)
        requires sized_sentinel_for<sentinel_t<Base>, iterator_t<Base>>;
  };
}

[edit] Class template std::ranges::take_view

namespace std::ranges {
  template<view V>
  class take_view : public view_interface<take_view<V>> {
  private:
    V base_ = V();                     // exposition only
    range_difference_t<V> count_ = 0;  // exposition only
    // class template take_view​::​sentinel
    template<bool> struct sentinel;    // exposition only
  public:
    take_view() = default;
    constexpr take_view(V base, range_difference_t<V> count);
 
    constexpr V base() const& requires copy_constructible<V> { return base_; }
    constexpr V base() && { return std::move(base_); }
 
    constexpr auto begin() requires (!__SimpleView<V>) {
      if constexpr (sized_range<V>) {
        if constexpr (random_access_range<V>)
          return ranges::begin(base_);
        else {
          auto sz = size();
          return counted_iterator{ranges::begin(base_), sz};
        }
      } else
        return counted_iterator{ranges::begin(base_), count_};
    }
 
    constexpr auto begin() const requires range<const V> {
      if constexpr (sized_range<const V>) {
        if constexpr (random_access_range<const V>)
          return ranges::begin(base_);
        else {
          auto sz = size();
          return counted_iterator{ranges::begin(base_), sz};
        }
      } else
        return counted_iterator{ranges::begin(base_), count_};
    }
 
    constexpr auto end() requires (!__SimpleView<V>) {
      if constexpr (sized_range<V>) {
        if constexpr (random_access_range<V>)
          return ranges::begin(base_) + size();
        else
          return default_sentinel;
      } else
        return sentinel<false>{ranges::end(base_)};
    }
 
    constexpr auto end() const requires range<const V> {
      if constexpr (sized_range<const V>) {
        if constexpr (random_access_range<const V>)
          return ranges::begin(base_) + size();
        else
          return default_sentinel;
      } else
        return sentinel<true>{ranges::end(base_)};
    }
 
    constexpr auto size() requires sized_range<V> {
      auto n = ranges::size(base_);
      return ranges::min(n, static_cast<decltype(n)>(count_));
    }
 
    constexpr auto size() const requires sized_range<const V> {
      auto n = ranges::size(base_);
      return ranges::min(n, static_cast<decltype(n)>(count_));
    }
  };
 
  template<range R>
    take_view(R&&, range_difference_t<R>)
      -> take_view<views::all_t<R>>;
}

[edit] Class template std::ranges::take_view::sentinel

namespace std::ranges {
  template<view V>
  template<bool Const>
  class take_view<V>::sentinel {
  private:
    using Base = conditional_t<Const, const V, V>;  // exposition only
    using CI = counted_iterator<iterator_t<Base>>;  // exposition only
    sentinel_t<Base> end_ = sentinel_t<Base>();     // exposition only
  public:
    sentinel() = default;
    constexpr explicit sentinel(sentinel_t<Base> end);
    constexpr sentinel(sentinel<!Const> s)
      requires Const && convertible_to<sentinel_t<V>, sentinel_t<Base>>;
 
    constexpr sentinel_t<Base> base() const;
 
    friend constexpr bool operator==(const CI& y, const sentinel& x);
  };
}

[edit] Class template std::ranges::take_while_view

namespace std::ranges {
  template<view V, class Pred>
    requires input_range<V> && is_object_v<Pred> &&
             indirect_unary_predicate<const Pred, iterator_t<V>>
  class take_while_view : public view_interface<take_while_view<V, Pred>> {
    // class template take_while_view​::​sentinel
    template<bool> class sentinel;  // exposition only
 
    V base_ = V();                  // exposition only
    __SemiregularBox<Pred> pred_;   // exposition only
 
  public:
    take_while_view() = default;
    constexpr take_while_view(V base, Pred pred);
 
    constexpr V base() const& requires copy_constructible<V> { return base_; }
    constexpr V base() && { return std::move(base_); }
 
    constexpr const Pred& pred() const;
 
    constexpr auto begin() requires (!__SimpleView<V>)
    { return ranges::begin(base_); }
 
    constexpr auto begin() const requires range<const V>
    { return ranges::begin(base_); }
 
    constexpr auto end() requires (!__SimpleView<V>)
    { return sentinel<false>(ranges::end(base_), addressof(*pred_)); }
 
    constexpr auto end() const requires range<const V>
    { return sentinel<true>(ranges::end(base_), addressof(*pred_)); }
  };
 
  template<class R, class Pred>
    take_while_view(R&&, Pred) -> take_while_view<views::all_t<R>, Pred>;
}

[edit] Class template std::ranges::take_while_view​::​sentinel

namespace std::ranges {
  template<view V, class Pred>
    requires input_range<V> && is_object_v<Pred> &&
             indirect_unary_predicate<const Pred, iterator_t<V>>
  template<bool Const>
  class take_while_view<V, Pred>::sentinel {        // exposition only
    using Base = conditional_t<Const, const V, V>;  // exposition only
 
    sentinel_t<Base> end_ = sentinel_t<Base>();     // exposition only
    const Pred* pred_ = nullptr;                    // exposition only
  public:
    sentinel() = default;
    constexpr explicit sentinel(sentinel_t<Base> end, const Pred* pred);
    constexpr sentinel(sentinel<!Const> s)
      requires Const && convertible_to<sentinel_t<V>, sentinel_t<Base>>;
 
    constexpr sentinel_t<Base> base() const { return end_; }
 
    friend constexpr bool operator==(const iterator_t<Base>& x, const sentinel& y);
  };
}

[edit] Class template std::ranges::drop_view

namespace std::ranges {
  template<view V>
  class drop_view : public view_interface<drop_view<V>> {
  public:
    drop_view() = default;
    constexpr drop_view(V base, range_difference_t<V> count);
 
    constexpr V base() const& requires copy_constructible<V> { return base_; }
    constexpr V base() && { return std::move(base_); }
 
    constexpr auto begin()
      requires (!(__SimpleView<V> && random_access_range<V>));
    constexpr auto begin() const
      requires random_access_range<const V>;
 
    constexpr auto end()
      requires (!__SimpleView<V>)
    { return ranges::end(base_); }
 
    constexpr auto end() const
      requires range<const V>
    { return ranges::end(base_); }
 
    constexpr auto size()
      requires sized_range<V>
    {
      const auto s = ranges::size(base_);
      const auto c = static_cast<decltype(s)>(count_);
      return s < c ? 0 : s - c;
    }
 
    constexpr auto size() const
      requires sized_range<const V>
    {
      const auto s = ranges::size(base_);
      const auto c = static_cast<decltype(s)>(count_);
      return s < c ? 0 : s - c;
    }
  private:
    V base_ = V();                     // exposition only
    range_difference_t<V> count_ = 0;  // exposition only
  };
 
  template<class R>
    drop_view(R&&, range_difference_t<R>) -> drop_view<views::all_t<R>>;
}

[edit] Class template std::ranges::drop_while_view

namespace std::ranges {
  template<view V, class Pred>
    requires input_range<V> && is_object_v<Pred> &&
             indirect_unary_predicate<const Pred, iterator_t<V>>
  class drop_while_view : public view_interface<drop_while_view<V, Pred>> {
  public:
    drop_while_view() = default;
    constexpr drop_while_view(V base, Pred pred);
 
    constexpr V base() const& requires copy_constructible<V> { return base_; }
    constexpr V base() && { return std::move(base_); }
 
    constexpr const Pred& pred() const;
 
    constexpr auto begin();
 
    constexpr auto end()
    { return ranges::end(base_); }
 
  private:
    V base_ = V();                 // exposition only
    __SemiregularBox<Pred> pred_;  // exposition only
  };
 
  template<class R, class Pred>
    drop_while_view(R&&, Pred) -> drop_while_view<views::all_t<R>, Pred>;
}

[edit] Class template std::ranges::join_view

namespace std::ranges {
  template<input_range V>
    requires view<V> && input_range<range_reference_t<V>> &&
             (is_reference_v<range_reference_t<V>> ||
              view<range_value_t<V>>)
  class join_view : public view_interface<join_view<V>> {
  private:
    using InnerRng =                 // exposition only
      range_reference_t<V>;
    // class template join_view​::​iterator
    template<bool Const>
      struct iterator;               // exposition only
    // class template join_view​::​sentinel
    template<bool Const>
      struct sentinel;               // exposition only
 
    V base_ = V();                   // exposition only
    views::all_t<InnerRng> inner_ =  // exposition only, present only
      views::all_t<InnerRng>();      // when !is_reference_v<InnerRng>
  public:
    join_view() = default;
    constexpr explicit join_view(V base);
 
    constexpr V base() const& requires copy_constructible<V> { return base_; }
    constexpr V base() && { return std::move(base_); }
 
    constexpr auto begin() {
      constexpr bool use_const = __SimpleView<V> &&
                                 is_reference_v<range_reference_t<V>>;
      return iterator<use_const>{*this, ranges::begin(base_)};
    }
 
    constexpr auto begin() const
    requires input_range<const V> &&
             is_reference_v<range_reference_t<const V>> {
      return iterator<true>{*this, ranges::begin(base_)};
    }
 
    constexpr auto end() {
      if constexpr (forward_range<V> &&
                    is_reference_v<InnerRng> && forward_range<InnerRng> &&
                    common_range<V> && common_range<InnerRng>)
        return iterator<__SimpleView<V>>{*this, ranges::end(base_)};
      else
        return sentinel<__SimpleView<V>>{*this};
    }
 
    constexpr auto end() const
    requires input_range<const V> &&
             is_reference_v<range_reference_t<const V>> {
      if constexpr (forward_range<const V> &&
                    is_reference_v<range_reference_t<const V>> &&
                    forward_range<range_reference_t<const V>> &&
                    common_range<const V> &&
                    common_range<range_reference_t<const V>>)
        return iterator<true>{*this, ranges::end(base_)};
      else
        return sentinel<true>{*this};
    }
  };
 
  template<class R>
    explicit join_view(R&&) -> join_view<views::all_t<R>>;
}

[edit] Class template std::ranges::join_view::iterator

namespace std::ranges {
  template<input_range V>
    requires view<V> && input_range<range_reference_t<V>> &&
             (is_reference_v<range_reference_t<V>> ||
              view<range_value_t<V>>)
  template<bool Const>
  struct join_view<V>::iterator {
  private:
    using Parent =                                       // exposition only
      conditional_t<Const, const join_view, join_view>;
    using Base   = conditional_t<Const, const V, V>;     // exposition only
 
    static constexpr bool __RefIsGlvalue =               // exposition only
      is_reference_v<range_reference_t<Base>>;
 
    iterator_t<Base> outer_ = iterator_t<Base>();        // exposition only
    iterator_t<range_reference_t<Base>> inner_ =         // exposition only
      iterator_t<range_reference_t<Base>>();
    Parent* parent_ = nullptr;                           // exposition only
 
    constexpr void satisfy();                            // exposition only
  public:
    using iterator_concept  = /* see definition */;
    using iterator_category = /* see definition */;
    using value_type        = range_value_t<range_reference_t<Base>>;
    using difference_type   = /* see definition */;
 
    iterator() = default;
    constexpr iterator(Parent& parent, iterator_t<Base> outer);
    constexpr iterator(iterator<!Const> i)
      requires Const &&
               convertible_to<iterator_t<V>, iterator_t<Base>> &&
               convertible_to<iterator_t<InnerRng>,
                              iterator_t<range_reference_t<Base>>>;
 
    constexpr decltype(auto) operator*() const { return *inner_; }
 
    constexpr iterator_t<Base> operator->() const
      requires __HasArrow<iterator_t<Base>> && copyable<iterator_t<Base>>;
 
    constexpr iterator& operator++();
    constexpr void operator++(int);
    constexpr iterator operator++(int)
      requires __RefIsGlvalue && forward_range<Base> &&
               forward_range<range_reference_t<Base>>;
 
    constexpr iterator& operator--()
      requires __RefIsGlvalue && bidirectional_range<Base> &&
               bidirectional_range<range_reference_t<Base>> &&
               common_range<range_reference_t<Base>>;
 
    constexpr iterator operator--(int)
      requires __RefIsGlvalue && bidirectional_range<Base> &&
               bidirectional_range<range_reference_t<Base>> &&
               common_range<range_reference_t<Base>>;
 
    friend constexpr bool operator==(const iterator& x, const iterator& y)
      requires __RefIsGlvalue && equality_comparable<iterator_t<Base>> &&
               equality_comparable<iterator_t<range_reference_t<Base>>>;
 
    friend constexpr decltype(auto) iter_move(const iterator& i)
    noexcept(noexcept(ranges::iter_move(i.inner_))) {
      return ranges::iter_move(i.inner_);
    }
 
    friend constexpr void iter_swap(const iterator& x, const iterator& y)
      noexcept(noexcept(ranges::iter_swap(x.inner_, y.inner_)));
  };
}

[edit] Class template std::ranges::join_view::sentinel

namespace std::ranges {
  template<input_range V>
    requires view<V> && input_range<range_reference_t<V>> &&
             (is_reference_v<range_reference_t<V>> ||
              view<range_value_t<V>>)
  template<bool Const>
  struct join_view<V>::sentinel {
  private:
    using Parent =                                      // exposition only
      conditional_t<Const, const join_view, join_view>;
    using Base   = conditional_t<Const, const V, V>;    // exposition only
    sentinel_t<Base> end_ = sentinel_t<Base>();         // exposition only
  public:
    sentinel() = default;
 
    constexpr explicit sentinel(Parent& parent);
    constexpr sentinel(sentinel<!Const> s)
      requires Const && convertible_to<sentinel_t<V>, sentinel_t<Base>>;
 
    friend constexpr bool operator==(const iterator<Const>& x, const sentinel& y);
  };
}

[edit] Class template std::ranges::split_view

namespace std::ranges {
  template<auto> struct __RequireConstant;  // exposition only
 
  template<class R>
  concept __TinyRange =  // exposition only
    sized_range<R> &&
    requires { typename __RequireConstant<remove_reference_t<R>::size()>; } &&
    (remove_reference_t<R>::size() <= 1);
 
  template<input_range V, forward_range Pattern>
    requires view<V> && view<Pattern> &&
             indirectly_comparable<iterator_t<V>, iterator_t<Pattern>, ranges::equal_to> &&
             (forward_range<V> || __TinyRange<Pattern>)
  class split_view : public view_interface<split_view<V, Pattern>> {
  private:
    V base_ = V();                             // exposition only
    Pattern pattern_ = Pattern();              // exposition only
    iterator_t<V> current_ = iterator_t<V>();  // exposition only, present only
                                               // if !forward_range<V>
    // class template split_view​::​__OuterIterator
    template<bool> struct __OuterIterator;     // exposition only
    // class template split_view​::​__InnerIterator
    template<bool> struct __InnerIterator;     // exposition only
  public:
    split_view() = default;
    constexpr split_view(V base, Pattern pattern);
 
    template<input_range R>
      requires constructible_from<V, views::all_t<R>> &&
               constructible_from<Pattern, single_view<range_value_t<R>>>
    constexpr split_view(R&& r, range_value_t<R> e);
 
    constexpr V base() const& requires copy_constructible<V> { return base_; }
    constexpr V base() && { return std::move(base_); }
 
    constexpr auto begin() {
      if constexpr (forward_range<V>)
        return __OuterIterator<__SimpleView<V>>{*this, ranges::begin(base_)};
      else {
        current_ = ranges::begin(base_);
        return __OuterIterator<false>{*this};
      }
    }
 
    constexpr auto begin() const requires forward_range<V> && forward_range<const V> {
      return __OuterIterator<true>{*this, ranges::begin(base_)};
    }
 
    constexpr auto end() requires forward_range<V> && common_range<V> {
      return __OuterIterator<__SimpleView<V>>{*this, ranges::end(base_)};
    }
 
    constexpr auto end() const {
      if constexpr (forward_range<V> && forward_range<const V> && common_range<const V>)
        return __OuterIterator<true>{*this, ranges::end(base_)};
      else
        return default_sentinel;
    }
  };
 
  template<class R, class P>
    split_view(R&&, P&&) -> split_view<views::all_t<R>, views::all_t<P>>;
 
  template<input_range R>
    split_view(R&&, range_value_t<R>)
      -> split_view<views::all_t<R>, single_view<range_value_t<R>>>;
}

[edit] Class template std::ranges::split_view::__OuterIterator

namespace std::ranges {
  template<input_range V, forward_range Pattern>
    requires view<V> && view<Pattern> &&
             indirectly_comparable<iterator_t<V>, iterator_t<Pattern>, ranges::equal_to> &&
             (forward_range<V> || __TinyRange<Pattern>)
  template<bool Const>
  struct split_view<V, Pattern>::__OuterIterator {
  private:
    using Parent =                          // exposition only
      conditional_t<Const, const split_view, split_view>;
    using Base   =                          // exposition only
      conditional_t<Const, const V, V>;
    Parent* parent_ = nullptr;              // exposition only
    iterator_t<Base> current_ =             // exposition only, present only
      iterator_t<Base>();                   // if V models forward_range
 
  public:
    using iterator_concept  =
      conditional_t<forward_range<Base>, forward_iterator_tag, input_iterator_tag>;
    using iterator_category = input_iterator_tag;
    // class split_view​::​__OuterIterator​::​value_type
    struct value_type;
    using difference_type   = range_difference_t<Base>;
 
    __OuterIterator() = default;
    constexpr explicit __OuterIterator(Parent& parent)
      requires (!forward_range<Base>);
    constexpr __OuterIterator(Parent& parent, iterator_t<Base> current)
      requires forward_range<Base>;
    constexpr __OuterIterator(__OuterIterator<!Const> i)
      requires Const && convertible_to<iterator_t<V>, iterator_t<Base>>;
 
    constexpr value_type operator*() const;
 
    constexpr __OuterIterator& operator++();
    constexpr decltype(auto) operator++(int) {
      if constexpr (forward_range<Base>) {
        auto tmp = *this;
        ++*this;
        return tmp;
      } else
        ++*this;
    }
 
    friend constexpr bool operator==(const __OuterIterator& x, const __OuterIterator& y)
      requires forward_range<Base>;
 
    friend constexpr bool operator==(const __OuterIterator& x, default_sentinel_t);
  };
}

[edit] Class std::ranges::split_view::__OuterIterator::value_type

namespace std::ranges {
  template<input_range V, forward_range Pattern>
    requires view<V> && view<Pattern> &&
             indirectly_comparable<iterator_t<V>, iterator_t<Pattern>, ranges::equal_to> &&
             (forward_range<V> || __TinyRange<Pattern>)
  template<bool Const>
  struct split_view<V, Pattern>::__OuterIterator<Const>::value_type
    : view_interface<value_type> {
  private:
    __OuterIterator i_ = __OuterIterator();  // exposition only
  public:
    value_type() = default;
    constexpr explicit value_type(__OuterIterator i);
 
    constexpr __InnerIterator<Const> begin() const requires copyable<__OuterIterator>;
    constexpr __InnerIterator<Const> begin() requires (!copyable<__OuterIterator>);
    constexpr default_sentinel_t end() const;
  };
}

[edit] Class template std::ranges::split_view::__InnerIterator

namespace std::ranges {
  template<input_range V, forward_range Pattern>
    requires view<V> && view<Pattern> &&
             indirectly_comparable<iterator_t<V>, iterator_t<Pattern>, ranges::equal_to> &&
             (forward_range<V> || __TinyRange<Pattern>)
  template<bool Const>
  struct split_view<V, Pattern>::__InnerIterator {
  private:
    using Base = conditional_t<Const, const V, V>;         // exposition only
    __OuterIterator<Const> i_ = __OuterIterator<Const>();  // exposition only
    bool incremented_ = false;                             // exposition only
  public:
    using iterator_concept  = typename __OuterIterator<Const>::iterator_concept;
    using iterator_category = /* see definition */;
    using value_type        = range_value_t<Base>;
    using difference_type   = range_difference_t<Base>;
 
    __InnerIterator() = default;
    constexpr explicit __InnerIterator(__OuterIterator<Const> i);
 
    constexpr decltype(auto) operator*() const { return *i_.current; }
 
    constexpr __InnerIterator& operator++();
    constexpr decltype(auto) operator++(int) {
      if constexpr (forward_range<V>) {
        auto tmp = *this;
        ++*this;
        return tmp;
      } else
        ++*this;
    }
 
    friend constexpr bool operator==(const __InnerIterator& x, const __InnerIterator& y)
      requires forward_range<Base>;
 
    friend constexpr bool operator==(const __InnerIterator& x, default_sentinel_t);
 
    friend constexpr decltype(auto) iter_move(const __InnerIterator& i)
    noexcept(noexcept(ranges::iter_move(i.i_.current))) {
      return ranges::iter_move(i.i_.current);
    }
 
    friend constexpr void iter_swap(const __InnerIterator& x, const __InnerIterator& y)
      noexcept(noexcept(ranges::iter_swap(x.i_.current, y.i_.current)))
      requires indirectly_swappable<iterator_t<Base>>;
  };
}

[edit] Class template std::ranges::common_view

namespace std::ranges {
  template<view V>
    requires (!common_range<V> && copyable<iterator_t<V>>)
  class common_view : public view_interface<common_view<V>> {
  private:
    V base_ = V();  // exposition only
  public:
    common_view() = default;
 
    constexpr explicit common_view(V r);
 
    template<viewable_range R>
      requires (!common_range<R> && constructible_from<V, views::all_t<R>>)
    constexpr explicit common_view(R&& r);
 
    constexpr V base() const& requires copy_constructible<V> { return base_; }
    constexpr V base() && { return std::move(base_); }
 
    constexpr auto begin() {
      if constexpr (random_access_range<V> && sized_range<V>)
        return ranges::begin(base_);
      else
        return common_iterator<iterator_t<V>, sentinel_t<V>>(ranges::begin(base_));
    }
 
    constexpr auto begin() const requires range<const V> {
      if constexpr (random_access_range<const V> && sized_range<const V>)
        return ranges::begin(base_);
      else
        return common_iterator<iterator_t<const V>, sentinel_t<const V>>(ranges::begin(base_));
    }
 
    constexpr auto end() {
      if constexpr (random_access_range<V> && sized_range<V>)
        return ranges::begin(base_) + ranges::size(base_);
      else
        return common_iterator<iterator_t<V>, sentinel_t<V>>(ranges::end(base_));
    }
 
    constexpr auto end() const requires range<const V> {
      if constexpr (random_access_range<const V> && sized_range<const V>)
        return ranges::begin(base_) + ranges::size(base_);
      else
        return common_iterator<iterator_t<const V>, sentinel_t<const V>>(ranges::end(base_));
    }
 
    constexpr auto size() requires sized_range<V> {
      return ranges::size(base_);
    }
    constexpr auto size() const requires sized_range<const V> {
      return ranges::size(base_);
    }
  };
 
  template<class R>
    common_view(R&&) -> common_view<views::all_t<R>>;
}

[edit] Class template std::ranges::reverse_view

namespace std::ranges {
  template<view V>
    requires bidirectional_range<V>
  class reverse_view : public view_interface<reverse_view<V>> {
  private:
    V base_ = V();  // exposition only
  public:
    reverse_view() = default;
 
    constexpr explicit reverse_view(V r);
 
    constexpr V base() const& requires copy_constructible<V> { return base_; }
    constexpr V base() && { return std::move(base_); }
 
    constexpr reverse_iterator<iterator_t<V>> begin();
    constexpr reverse_iterator<iterator_t<V>> begin() requires common_range<V>;
    constexpr auto begin() const requires common_range<const V>;
 
    constexpr reverse_iterator<iterator_t<V>> end();
    constexpr auto end() const requires common_range<const V>;
 
    constexpr auto size() requires sized_range<V> {
      return ranges::size(base_);
    }
    constexpr auto size() const requires sized_range<const V> {
      return ranges::size(base_);
    }
  };
 
  template<class R>
    reverse_view(R&&) -> reverse_view<views::all_t<R>>;
}

[edit] Class template std::ranges::elements_view

namespace std::ranges {
  template<class T, size_t N>
  concept __HasTupleElement =  // exposition only
    requires(T t) {
      typename tuple_size<T>::type;
      requires N < tuple_size_v<T>;
      typename tuple_element_t<N, T>;
      { get<N>(t) } -> convertible_to<const tuple_element_t<N, T>&>;
    };
 
  template<input_range V, size_t N>
    requires view<V> && __HasTupleElement<range_value_t<V>, N> &&
             __HasTupleElement<remove_reference_t<range_reference_t<V>>, N>
  class elements_view : public view_interface<elements_view<V, N>> {
  public:
    elements_view() = default;
    constexpr explicit elements_view(V base);
 
    constexpr V base() const& requires copy_constructible<V> { return base_; }
    constexpr V base() && { return std::move(base_); }
 
    constexpr auto begin() requires (!__SimpleView<V>)
    { return iterator<false>(ranges::begin(base_)); }
 
    constexpr auto begin() const requires __SimpleView<V>
    { return iterator<true>(ranges::begin(base_)); }
 
    constexpr auto end()
    { return sentinel<false>{ranges::end(base_)}; }
 
    constexpr auto end() requires common_range<V>
    { return iterator<false>{ranges::end(base_)}; }
 
    constexpr auto end() const requires range<const V>
    { return sentinel<true>{ranges::end(base_)}; }
 
    constexpr auto end() const requires common_range<const V>
    { return iterator<true>{ranges::end(base_)}; }
 
    constexpr auto size() requires sized_range<V>
    { return ranges::size(base_); }
 
    constexpr auto size() const requires sized_range<const V>
    { return ranges::size(base_); }
 
  private:
    // class template elements_view​::​iterator
    template<bool> struct iterator;  // exposition only
    // class template elements_view​::​sentinel
    template<bool> struct sentinel;  // exposition only
    V base_ = V();                   // exposition only
  };
}

[edit] Class template std::ranges::elements_view::iterator

namespace std::ranges {
  template<input_range V, size_t N>
    requires view<V> && __HasTupleElement<range_value_t<V>, N> &&
             __HasTupleElement<remove_reference_t<range_reference_t<V>>, N>
  template<bool Const>
  class elements_view<V, N>::iterator {             // exposition only
    using Base = conditional_t<Const, const V, V>;  // exposition only
 
    iterator_t<Base> current_ = iterator_t<Base>();
  public:
    using iterator_category = typename iterator_traits<iterator_t<Base>>::iterator_category;
    using value_type = remove_cvref_t<tuple_element_t<N, range_value_t<Base>>>;
    using difference_type = range_difference_t<Base>;
 
    iterator() = default;
    constexpr explicit iterator(iterator_t<Base> current);
    constexpr iterator(iterator<!Const> i)
      requires Const && convertible_to<iterator_t<V>, iterator_t<Base>>;
 
    constexpr iterator_t<Base> base() const&
      requires copyable<iterator_t<Base>>;
    constexpr iterator_t<Base> base() &&;
 
    constexpr decltype(auto) operator*() const
    { return get<N>(*current_); }
 
    constexpr iterator& operator++();
    constexpr void operator++(int) requires (!forward_range<Base>);
    constexpr iterator operator++(int) requires forward_range<Base>;
 
    constexpr iterator& operator--() requires bidirectional_range<Base>;
    constexpr iterator operator--(int) requires bidirectional_range<Base>;
 
    constexpr iterator& operator+=(difference_type x)
      requires random_access_range<Base>;
    constexpr iterator& operator-=(difference_type x)
      requires random_access_range<Base>;
 
    constexpr decltype(auto) operator[](difference_type n) const
      requires random_access_range<Base>
    { return get<N>(*(current_ + n)); }
 
    friend constexpr bool operator==(const iterator& x, const iterator& y)
      requires equality_comparable<iterator_t<Base>>;
 
    friend constexpr bool operator<(const iterator& x, const iterator& y)
      requires random_access_range<Base>;
    friend constexpr bool operator>(const iterator& x, const iterator& y)
      requires random_access_range<Base>;
    friend constexpr bool operator<=(const iterator& y, const iterator& y)
      requires random_access_range<Base>;
    friend constexpr bool operator>=(const iterator& x, const iterator& y)
      requires random_access_range<Base>;
    friend constexpr auto operator<=>(const iterator& x, const iterator& y)
      requires random_access_range<Base> && three_way_comparable<iterator_t<Base>>;
 
    friend constexpr iterator operator+(const iterator& x, difference_type y)
      requires random_access_range<Base>;
    friend constexpr iterator operator+(difference_type x, const iterator& y)
      requires random_access_range<Base>;
    friend constexpr iterator operator-(const iterator& x, difference_type y)
      requires random_access_range<Base>;
    friend constexpr difference_type operator-(const iterator& x, const iterator& y)
      requires random_access_range<Base>;
  };
}

[edit] Class template std::ranges::elements_view::sentinel

namespace std::ranges {
  template<input_range V, size_t N>
    requires view<V> && __HasTupleElement<range_value_t<V>, N> &&
             __HasTupleElement<remove_reference_t<range_reference_t<V>>, N>
  template<bool Const>
  class elements_view<V, N>::sentinel {             // exposition only
  private:
    using Base = conditional_t<Const, const V, V>;  // exposition only
    sentinel_t<Base> end_ = sentinel_t<Base>();     // exposition only
  public:
    sentinel() = default;
    constexpr explicit sentinel(sentinel_t<Base> end);
    constexpr sentinel(sentinel<!Const> other)
      requires Const && convertible_to<sentinel_t<V>, sentinel_t<Base>>;
 
    constexpr sentinel_t<Base> base() const;
 
    friend constexpr bool operator==(const iterator<Const>& x, const sentinel& y);
 
    friend constexpr range_difference_t<Base>
      operator-(const iterator<Const>& x, const sentinel& y)
        requires sized_sentinel_for<sentinel_t<Base>, iterator_t<Base>>;
 
    friend constexpr range_difference_t<Base>
      operator-(const sentinel& x, const iterator<Const>& y)
        requires sized_sentinel_for<sentinel_t<Base>, iterator_t<Base>>;
  };
}