Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::ssize

      From cppreference.com
      <cpp‎ |ranges
       
       
      Ranges library
      Range adaptors
       
      Defined in header<ranges>
      Defined in header<iterator>
      inlinenamespace/* unspecified */{

         inlineconstexpr/* unspecified */ ssize=/* unspecified */;

      }
      (since C++20)
      (customization point object)
      Call signature
      template<class T>

          requires/* see below */

      constexprauto ssize( T&& t);
      (since C++20)

      Calculates the number of elements int in constant time, and converts the result to a signed type.

      Given thesubexpression of whicht denotes the (possiblymaterialized) result object asE:

      Contents

      Customization point objects

      The nameranges::ssize denotes acustomization point object, which is a constfunction object of aliteralsemiregular class type. SeeCustomizationPointObject for details.

      [edit]Notes

      Ifranges::ssize(e) is valid for an expressione, the return type is asigned-integer-like type.

      [edit]Example

      Run this code
      #include <array>#include <iostream>#include <ranges>#include <type_traits> int main(){std::array arr{1,2,3,4,5};auto s= std::ranges::ssize(arr); std::cout<<"ranges::ssize(arr) = "<< s<<'\n'<<"ranges::ssize is "<<(std::is_signed_v<decltype(s)>?"signed":"unsigned")<<'\n'; std::cout<<"reversed arr: "; for(--s; s>=0;--s)std::cout<< arr[s]<<' '; std::cout<<"\n""s = "<< s<<'\n';}

      Output:

      ranges::ssize(arr) = 5ranges::ssize is signedreversed arr: 5 4 3 2 1s = -1

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 3403C++20ranges::size worked for some non-range types butranges::ssize did notmade work

      [edit]See also

      returns an integer equal to the size of a range
      (customization point object)[edit]
      specifies that a range knows its size in constant time
      (concept)[edit]
      returns the distance between an iterator and a sentinel, or between the beginning and end of a range
      (algorithm function object)[edit]
      (C++17)(C++20)
      returns the size of a container or array
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/ssize&oldid=176013"

      [8]ページ先頭

      ©2009-2025 Movatter.jp