Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::iota_view<W, Bound>::size

      From cppreference.com
      <cpp‎ |ranges‎ |iota view
       
       
      Ranges library
      Range adaptors
       
      std::ranges::iota_view
      Member functions
      iota_view::size
      Deduction guides
      Nested classes
      Iterator
      Helper concepts
      Member types
      Member functions
      Non-member functions
      Sentinel
      Member functions
      Non-member functions
       
      constexprauto size()const

          requires(std::same_as<W, Bound>&&/*advanceable*/<W>)||
                   (/*is-integer-like*/<W>&&/*is-integer-like*/<Bound>)||

                   std::sized_sentinel_for<Bound, W>;
      (since C++20)

      Returns the size of the view if the view is bounded.

      For the definitions of/*advanceable*/ and/*is-integer-like*/, seeadvanceable andis-integer-like respectively.

      Contents

      [edit]Return value

      If any ofW andBound is not ainteger-like type, returnsto-unsigned-like (bound_ - value_ ).

      Otherwise, returns(value_ <0)?
          (
              (bound_ <0)?
                  to-unsigned-like (-value_ )- to-unsigned-like (-bound_ ):
                  to-unsigned-like (bound_ )+ to-unsigned-like (-value_ )
          ):
          to-unsigned-like (bound_ )- to-unsigned-like (value_ )
      .

      [edit]Example

      Run this code
      #include <cassert>#include <ranges> int main(){unsigned initial_value{1}, bound{5};auto i{std::views::iota(initial_value, bound)};assert(i.size()== bound- initial_value and i.size()==4); auto u{std::views::iota(8)};// assert(u.size()); // Error: size() is not present since “u” is unbounded}

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      LWG 3610C++20size might reject integer-class typesaccept if possible

      [edit]See also

      returns an 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]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/iota_view/size&oldid=176920"

      [8]ページ先頭

      ©2009-2025 Movatter.jp