Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::views::repeat,std::ranges::repeat_view

      From cppreference.com
      <cpp‎ |ranges
       
       
      Ranges library
      Range adaptors
       
       
      Defined in header<ranges>
      template<std::move_constructible W,

               std::semiregular Bound=std::unreachable_sentinel_t>
          requires(std::is_object_v<W>&&std::same_as<W,std::remove_cv_t<W>>&&
                   (/*integer-like-with-usable-difference-type*/<Bound>||
                   std::same_as<Bound,std::unreachable_sentinel_t>))

      class repeat_view:publicranges::view_interface<repeat_view<W, Bound>>
      (1)(since C++23)
      namespace views{

         inlineconstexpr/* unspecified */ repeat=/* unspecified */;

      }
      (2)(since C++23)
      Call signature
      template<class W>

          requires/* see below */

      constexpr/* see below */ repeat( W&& value);
      (since C++23)
      template<class W,class Bound>

          requires/* see below */

      constexpr/* see below */ repeat( W&& value, Bound&& bound);
      (since C++23)
      Helper concepts
      concept/*integer-like-with-usable-difference-type*/=

         /*is-signed-integer-like*/<T>||

         (/*is-integer-like*/<T>&&std::weakly_incrementable<T>)
      (3)(exposition only*)
      1) A range factory that generates a sequence of elements by repeatedly producing the same value. Can be either bounded or unbounded (infinite).
      2)views::repeat(e) andviews::repeat(e, f) areexpression-equivalent torepeat_view<std::decay_t<decltype((E))>>(e) andrepeat_view(e, f) respectively for any suitable subexpressionse andf.
      3) Determines whether a type isinteger-like and has a usabledifference type.

      repeat_view modelsrandom_access_range. IfBound is notstd::unreachable_sentinel_t,repeat_view also modelssized_range andcommon_range.

      Contents

      Customization point objects

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

      [edit]Data members

      Member Definition
      movable-box <W>value_ the repeating element of the view
      (exposition-only member object*)
      Boundbound_ the sentinel value
      (exposition-only member object*)

      [edit]Member functions

      creates arepeat_view
      (public member function)
      obtains the beginning iterator of arepeat_view
      (public member function)
      obtains the sentinel denoting the end of arepeat_view
      (public member function)
      obtains the size of arepeat_view if it is sized
      (public member function)
      Inherited fromstd::ranges::view_interface
      returns whether the derived view is empty, provided only if it satisfiessized_range orforward_range
      (public member function ofstd::ranges::view_interface<D>)[edit]
      (C++23)
      returns a constant iterator to the beginning of the range
      (public member function ofstd::ranges::view_interface<D>)[edit]
      (C++23)
      returns a sentinel for the constant iterator of the range
      (public member function ofstd::ranges::view_interface<D>)[edit]
      returns whether the derived view is not empty, provided only ifranges::empty is applicable to it
      (public member function ofstd::ranges::view_interface<D>)[edit]
      returns the first element in the derived view, provided if it satisfiesforward_range
      (public member function ofstd::ranges::view_interface<D>)[edit]
      returns the last element in the derived view, provided only if it satisfiesbidirectional_range andcommon_range
      (public member function ofstd::ranges::view_interface<D>)[edit]
      returns thenth element in the derived view, provided only if it satisfiesrandom_access_range
      (public member function ofstd::ranges::view_interface<D>)[edit]

      std::ranges::repeat_view::repeat_view

      repeat_view() requiresstd::default_initializable<W>=default;
      (1)(since C++23)
      constexprexplicit repeat_view(const W& value, Bound bound= Bound());
      (2)(since C++23)
      constexprexplicit repeat_view( W&& value, Bound bound= Bound());
      (3)(since C++23)
      template<class...WArgs,class...BoundArgs>

          requiresstd::constructible_from<W, WArgs...>
               &&std::constructible_from<Bound, BoundArgs...>
      constexprexplicit
          repeat(std::piecewise_construct_t,std::tuple<WArgs...> value_args,

                 std::tuple<BoundArgs...> bound_args=std::tuple<>{});
      (4)(since C++23)
      1) Default-initializesvalue_ and value-initializesbound_ .
      2) Initializesvalue_ withvalue and initializesbound_ withbound.
      IfBound is notstd::unreachable_sentinel_t andbool(bound>=0) isfalse, the behavior is undefined.
      3) Initializesvalue_ withstd::move(value) and initializesbound_ withbound.
      IfBound is notstd::unreachable_sentinel_t andbool(bound>=0) isfalse, the behavior is undefined.
      4) Initializesvalue_ withstd::make_from_tuple<T>(std::move(value_args)) andbound_ withstd::make_from_tuple<Bound>(std::move(bound_args)).
      IfBound is notstd::unreachable_sentinel_t andbool(bound>=0) isfalse, the behavior is undefined.

      Parameters

      value - the value to be repeatedly produced
      bound - the bound
      value_args - the tuple containing the initializers ofvalue_
      bound_args - the tuple containing the initializers ofbound_

      std::ranges::repeat_view::begin

      constexpr/*iterator*/ begin()const;
      (since C++23)

      Returnsiterator (std::addressof(*value_ )).

      std::ranges::repeat_view::end

      constexpr/*iterator*/ end()const
          requires(!std::same_as<Bound,std::unreachable_sentinel_t>);
      (1)(since C++23)
      constexprstd::unreachable_sentinel_t end()const;
      (2)(since C++23)
      1) Returnsiterator (std::addressof(*value_ ), bound_ ).

      std::ranges::repeat_view::size

      constexprauto size()const
          requires(!std::same_as<Bound,std::unreachable_sentinel_t>);
      (since C++23)

      Returnsto-unsigned-like (bound_ ).

      [edit]Deduction guides

      template<class W,class Bound=std::unreachable_sentinel_t>
      repeat_view( W, Bound= Bound())-> repeat_view<W, Bound>;
      (since C++23)

      [edit]Nested classes

      the iterator type
      (exposition-only member class*)

      [edit]Notes

      Feature-test macroValueStdFeature
      __cpp_lib_ranges_repeat202207L(C++23)std::ranges::repeat_view

      [edit]Example

      Run this code
      #include <iostream>#include <ranges>#include <string_view>usingnamespace std::literals; int main(){// bounded overloadfor(auto s: std::views::repeat("C++"sv,3))std::cout<< s<<' ';std::cout<<'\n'; // unbounded overloadfor(auto s: std::views::repeat("I know that you know that"sv)| std::views::take(3))std::cout<< s<<' ';std::cout<<"...\n";}

      Output:

      C++ C++ C++I know that you know that I know that you know that I know that you know that ...

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      LWG 4053C++20unary calls toviews::repeat did not decay the argumentdecay the argument
      LWG 4054C++20callingviews::repeat with arepeat_view
      did not create a nestedrepeat_view
      creates a nested
      repeat_view

      [edit]See also

      aview consisting of a sequence generated by repeatedly incrementing an initial value
      (class template)(customization point object)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/repeat_view&oldid=176947"

      [8]ページ先頭

      ©2009-2025 Movatter.jp