Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::view,std::ranges::enable_view,std::ranges::view_base

      From cppreference.com
      <cpp‎ |ranges
       
       
      Ranges library
      Range adaptors
       
      Defined in header<ranges>
      template<class T>
      concept view=ranges::range<T>&&std::movable<T>&& ranges::enable_view<T>;
      (1)(since C++20)
      template<class T>

      constexprbool enable_view=

         std::derived_from<T, view_base>||/*is-derived-from-view-interface*/<T>;
      (2)(since C++20)
      struct view_base{};
      (3)(since C++20)
      1) Theview concept specifies the requirements of arange type that has suitable semantic properties for use in constructing range adaptor pipelines.
      2) Theenable_view variable template is used to indicate whether arange is aview./*is-derived-from-view-interface*/<T> istrue if and only ifT has exactly one public base classranges::view_interface<U> for some typeU, andT has no base classes of typeranges::view_interface<V> for any other typeV.
      Users may specializeenable_view totrue for cv-unqualified program-defined types which modelview, andfalse for types which do not. Such specializations must beusable in constant expressions and have typeconstbool.
      3) Deriving fromview_base enablesrange types to modelview.

      Contents

      [edit]Semantic requirements

      1)T modelsview only if:
      • move construction ofT has constant time complexity, and
      • if\(\scriptsize N\)N copies and/or moves are made from aT object holding\(\scriptsize M\)M elements, then these\(\scriptsize N\)N objects have\(\scriptsize \mathcal{O}{(N+M)}\)𝓞(N+M) destruction (which implies that a moved-fromview object has\(\scriptsize \mathcal{O}{(1)}\)𝓞(1) destruction), and
      • eitherstd::copy_constructible<T> isfalse, or copy construction ofT has constant time complexity, and
      • eitherstd::copyable<T> isfalse, or copy assignment ofT has no more time complexity than destruction followed by copy construction.

      [edit]Specializations

      Specializations ofenable_view for all specializations of the following standard templates are defined astrue:

      (since C++26)

      [edit]Notes

      Examples ofview types are:

      A copyable container such asstd::vector<std::string> generally does not meet the semantic requirements ofview since copying the container copies all of the elements, which cannot be done in constant time.

      While views were originally described as cheaply copyable and non-owning ranges, a type is not required to be copyable or non-owning for it to modelview. However, it must still be cheap to copy (if it is copyable), move, assign, and destroy, so thatrange adaptors will not have unexpected complexity.

      By default, a type modelingmovable andrange is considered a view if it is publicly and unambiguously derived fromview_base, or exactly one specialization ofstd::ranges::view_interface.

      [edit]Example

      A minimum view.

      #include <ranges> struct ArchetypalView: std::ranges::view_interface<ArchetypalView>{int* begin();int* end();}; static_assert(std::ranges::view<ArchetypalView>);

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      P2325R3C++20view requireddefault_initializabledoes not require
      LWG 3549C++20enable_view did not detect inheritance fromview_interfacedetects
      P2415R2C++20the restriction on the time complexity of destruction was too strictrelaxed
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/view&oldid=173219"

      [8]ページ先頭

      ©2009-2025 Movatter.jp