Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::sized_range,std::ranges::disable_sized_range

      From cppreference.com
      <cpp‎ |ranges
       
       
      Ranges library
      Range adaptors
       
      Defined in header<ranges>
      (1)
      template<class T>

      concept sized_range=ranges::range<T>&&
          requires(T& t){
             ranges::size(t);

         };
      (since C++20)
      (until C++26)
      template<class T>

      concept sized_range= ranges::approximately_sized_range<T>&&
          requires(T& t){
             ranges::size(t);

         };
      (since C++26)
      template<class>
      constexprbool disable_sized_range=false;
      (2)(since C++20)
      1) Thesized_range concept specifies the requirements of arange(until C++26)approximately_sized_range(since C++26) type that knows its size in constant time with thesize function.
      2) Thedisable_sized_range exists to allow use of range types that provide asize function (either as a member or as a non-member) but do not in fact modelsized_range. Users may specializedisable_sized_range for cv-unqualified program-defined types. Such specializations shall be usable inconstant expressions and have typeconstbool.

      Contents

      [edit]Semantic requirements

      1) Given an lvaluet of typestd::remove_reference_t<T>,T modelssized_range only if

      [edit]Notes

      disable_sized_range cannot be used to opt-out a range whose iterator and sentinel satisfysized_sentinel_for;std::disable_sized_sentinel_for must be used instead.

      disable_sized_range cannot be specialized for array types or reference types.

      Feature-test macroValueStdFeature
      __cpp_lib_ranges_reserve_hint202502L(C++26)ranges::approximately_sized_range andranges::reserve_hint

      [edit]Example

      Run this code
      #include <forward_list>#include <list>#include <ranges> static_assert(    std::ranges::sized_range<std::list<int>> and    not std::ranges::sized_range<std::forward_list<int>>); int main(){}

      [edit]See also

      specifies a range whose iterator type satisfiesrandom_access_iterator
      (concept)[edit]
      specifies a range whose iterator type satisfiescontiguous_iterator
      (concept)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/sized_range&oldid=182365"

      [8]ページ先頭

      ©2009-2025 Movatter.jp