Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::indirectly_writable

      From cppreference.com
      <cpp‎ |iterator
       
       
      Iterator library
      Iterator concepts
      indirectly_writable
      (C++20)
      Iterator primitives
      Algorithm concepts and utilities
      Indirect callable concepts
      Common algorithm requirements
      (C++20)
      (C++20)
      (C++20)
      Utilities
      (C++20)
      Iterator adaptors
      Range access
      (C++11)(C++14)
      (C++14)(C++14)  
      (C++11)(C++14)
      (C++14)(C++14)  
      (C++17)(C++20)
      (C++17)
      (C++17)
       
      Defined in header<iterator>
      template<class Out,class T>

          concept indirectly_writable=
              requires(Out&& o, T&& t){
                 *o=std::forward<T>(t);
                 *std::forward<Out>(o)=std::forward<T>(t);
                 const_cast<conststd::iter_reference_t<Out>&&>(*o)=std::forward<T>(t);
                 const_cast<conststd::iter_reference_t<Out>&&>(*std::forward<Out>(o))=
                     std::forward<T>(t);
             };

             /* none of the four expressions above are required to be equality-preserving */
      (since C++20)

      The conceptindirectly_writable<Out, T> specifies the requirements for writing a value whose type and value category are encoded byT into an iteratorOut's referenced object.

      [edit]Semantic requirements

      Lete be an expression such thatdecltype((e)) isT, ando be a dereferenceable object of typeOut, thenindirectly_writable<Out, T> is modeled only if:

      o is not required to be dereferenceable after evaluating any of the assignment expressions above. Ife is an xvalue, the resulting state of the object it denotes is valid but unspecified.

      [edit]Equality preservation

      Expressions declared inrequires expressions of the standard library concepts are required to beequality-preserving (except where stated otherwise).

      [edit]Notes

      The only valid use ofoperator* is on the left side of an assignment expression. Assignment through the same value of an indirectly writable type may happen only once.

      The required expressions withconst_cast preventindirectly_readable objects with prvaluereference types from satisfying the syntactic requirements ofindirectly_writable by accident, while permitting proxy references to continue to work as long as their constness is shallow. SeeRanges TS issue 381.

      struct Object{    Object& operator=(const Object& other)=default; int x;}; struct ProxyReference{    ProxyReference& operator=(const ProxyReference& other)=default; const ProxyReference& operator=(const Object& o)const{*p= o;return*this;}     Object* p;}; struct I1{ Object& operator*();}; struct I2{ Object operator*();}; struct I3{ ProxyReference operator*();}; static_assert(std::indirectly_writable<I1, Object>);static_assert(!std::indirectly_writable<I2, Object>);static_assert(std::indirectly_writable<I3, Object>);static_assert(!std::indirectly_writable<I3, ProxyReference>); void f(I1 i1, I2 i2, I3 i3, Object o){*i1= o;// OK, assigns to the value referenced by *i1 *i2= o;// OK, but meaningless: This assigns to the temporary returned by *i2 *i3= o;// OK, calls ProxyReference::operator=(const Object& o) const// which performs *ptr = o, where ptr is (*i3).p}
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/iterator/indirectly_writable&oldid=182915"

      [8]ページ先頭

      ©2009-2025 Movatter.jp