Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::experimental::ranges::distance

      From cppreference.com
      <cpp‎ |experimental‎ |ranges
       
       
       
       
      Iterators library
      Iterator concepts
      Indirect callable concepts
                                                        
                                                        
                                                        
      Common algorithm requirements
                                                        
      Concept utilities
      Iterator utilities and operations
      distance
      Iterator traits
      Iterator adaptors
      Stream iterators
       
      namespace{

         constexpr/* unspecified */ distance=/* unspecified */;

      }
      (ranges TS)
      (customization point object)
      Call signature
      template< Iterator I, Sentinel<I> S>
      constexpr ranges::difference_type_t<I> distance( I first, S last);
      (1)
      template< Range R>
      constexpr ranges::difference_type_t<ranges::iterator_t<R>> distance( R&& r);
      (2)
      template< SizedRange R>
      constexpr ranges::difference_type_t<ranges::iterator_t<R>> distance( R&& r);
      (3)

      Returns the distance betweenfirst andlast, or between the beginning and the end of the ranger.

      1) IfSizedSentinel<S, I> is satisfied, equivalent toreturn last- first;. Otherwise, returns the number of increments needed to get fromfirst tolast. If[firstlast) does not denote a range, thenI andS must be the same type and must modelSizedSentinel, and[lastfirst) must denote a range. Otherwise, the behavior is undefined.
      2) Equivalent toreturnranges::distance(ranges::begin(r),ranges::end(r));.
      3) Equivalent toreturnranges::size(r);.

      Instantiating overloads(2,3) may be ill-formed if the header<experimental/ranges/range> is not included before the point of instantiation.

      Contents

      [edit] Customization point objects

      The nameranges::distance denotes acustomization point object, which is afunction object of aliteralSemiregular class type (denoted, for exposition purposes, asDistanceT). All instances ofDistanceT are equal. Thus,ranges::distance can be copied freely and its copies can be used interchangeably.

      Given a set of typesArgs..., ifstd::declval<Args>()... meet the requirements for arguments toranges::distance above,DistanceT will satisfyranges::Invocable<const DistanceT, Args...>. Otherwise, no function call operator ofDistanceT participates in overload resolution.

      In every translation unit in whichranges::distance is defined, it refers to the same instance of the customization point object. (This means that it can be used freely in things like inline functions and function templates without violating theone-definition rule.)

      [edit]Return value

      The distance betweenfirst andlast, or between the beginning and the end of the ranger.

      [edit]Example

      This section is incomplete
      Reason: no example

      [edit]See also

      returns the distance between two iterators
      (function template)[edit]
      advances an iterator by given distance
      (function template)[edit]
      increment an iterator
      (function template)[edit]
      decrement an iterator
      (function template)[edit]
      obtains the size of a range whose size can be calculated in constant time
      (customization point object)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/experimental/ranges/iterator/distance&oldid=157771"

      [8]ページ先頭

      ©2009-2026 Movatter.jp