Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::concat_view<Views...>::size

      From cppreference.com
      <cpp‎ |ranges‎ |concat view
       
       
      Ranges library
      Range adaptors
       
      std::ranges::concat_view
      Member functions
      concat_view::size
      Deduction guides
      Iterator
      Member functions
      Non-member functions
       
      constexprauto size()
          requires(sized_range<Views>&& ...);
      (1)(since C++26)
      constexprauto size()const
          requires(sized_range<const Views>&& ...);
      (2)(since C++26)

      Returns the number of elements.

      Equivalent toreturnstd::apply
             (
                 [](auto...sizes)
                 {
                     using CT=ranges::common_type_t<decltype(sizes)...>;
                     return(make-unsigned-like-t <CT>(sizes)+ ...);
                 },
                 tuple-transform (ranges::size, views_ )
             );
      .

      Contents

      [edit]Return value

      As described above.

      [edit]Complexity

      Constant.

      [edit]Notes

      The complexity ofconcat_view is constant time (even though in some cases it is a linear function of the number of ranges it concatenates which is a statically known parameter of this view) because time complexity as required by the ranges concepts are formally expressed with respect to the total number of elements (the size) of a given range, and not to the statically known parameters of that range.

      [edit]Example

      The preliminary version can be checked out onCompiler Explorer.

      Run this code
      #include <cassert>#include <forward_list>#include <list>#include <ranges> int main(){constexprstaticauto a={1,2};constexprstaticauto b={1,2,3};constexprstaticauto c={1,2,3,4}; constexprauto con{std::views::concat(a, b, c)};    static_assert(std::ranges::sized_range<decltype(con)>);    static_assert(con.size()==2+3+4); std::forward_list d= b;    static_assert(not std::ranges::sized_range<std::forward_list<int>>);constauto cat{std::views::concat(b, c, d)};    static_assert(not std::ranges::sized_range<decltype(cat)>);//  auto x = cat.size(); // error: cat is not sized_range because of d std::list e= c;constauto dog{std::views::concat(a, b, e)};    static_assert(std::ranges::sized_range<decltype(dog)>);assert(dog.size()==2+3+4);}

      [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/concat_view/size&oldid=176611"

      [8]ページ先頭

      ©2009-2025 Movatter.jp