Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      C++ named requirements:MoveInsertable(since C++11)

      From cppreference.com
      <cpp‎ |named req
       
       
      C++ named requirements
       

      Specifies that an object of the type can be constructed into uninitialized storage from an rvalue of that type by a given allocator.

      Contents

      [edit]Requirements

      Given the following types, values and expressions:

      Type Definition
      T an object type
      A an allocator type
      X a container type satisfying all following conditions:
      Value Definition
      m an lvalue of typeA
      p a pointer of typeT*
      Expression Definition
      rv an expression denoting an rvalue of typeT
      exprstd::allocator_traits<A>::construct(m, p, rv)

      T isMoveInsertable intoX if all following conditions are satisfied:

      • expr is well-formed.
      • Right after the evaluation ofexpr, the value of*p is equivalent to the value ofrv before the evaluation.

      [edit]Notes

      IfA isstd::allocator<T>, then this will call placementnew, as by::new((void*)p) T(rv)(until C++20)std::construct_at(p, rv)(since C++20). This effectively requiresT to be move constructible.

      Ifstd::allocator<T> or a similar allocator is used, a class does not have to implement amove constructor to satisfy this type requirement: acopy constructor that takes aconst T& argument can bind rvalue expressions. If aMoveInsertable class implements a move constructor, it may also implementmove semantics to take advantage of the fact that the value ofrv after construction is unspecified.

      Although it is required that customizedconstruct is used when constructing elements ofstd::basic_string until C++23, all implementations only used the default mechanism. The requirement is corrected byP1072R10 to match existing practice.

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      LWG 2177C++11evalutingexpr did not have any postconditionadded

      [edit]See also

      CopyInsertable
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/named_req/MoveInsertable&oldid=177225"

      [8]ページ先頭

      ©2009-2025 Movatter.jp