Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::scoped_allocator_adaptor<OuterAlloc,InnerAlloc...>::construct

      From cppreference.com
      <cpp‎ |memory‎ |scoped allocator adaptor
       
       
      Memory management library
      (exposition only*)
      Allocators
      Uninitialized memory algorithms
      Constrained uninitialized memory algorithms
      Memory resources
      Uninitialized storage(until C++20)
      (until C++20*)
      (until C++20*)
      Garbage collector support(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
       
       
      Defined in header<scoped_allocator>
      template<class T,class...Args>
      void construct( T* p, Args&&...args);
      (1)
      template<class T1,class T2,class...Args1,class...Args2>

      void construct(std::pair<T1, T2>* p,std::piecewise_construct_t,

                     std::tuple<Args1...> x,std::tuple<Args2...> y);
      (2)(until C++20)
      template<class T1,class T2>
      void construct(std::pair<T1, T2>* p);
      (3)(until C++20)
      template<class T1,class T2,class U,class V>
      void construct(std::pair<T1, T2>* p, U&& x, V&& y);
      (4)(until C++20)
      template<class T1,class T2,class U,class V>
      void construct(std::pair<T1, T2>* p,conststd::pair<U, V>& xy);
      (5)(until C++20)
      template<class T1,class T2,class U,class V>
      void construct(std::pair<T1, T2>* p,std::pair<U, V>&& xy);
      (6)(until C++20)
      Helper function templates
      template<class T,class...Args>
      std::tuple</* see below */>/*concat-args*/(std::tuple<Args...>&& tup);
      (7)(exposition only*)
      (until C++20)

      Constructs an object in allocated, but not initialized storage pointed to byp using the outer allocator and the provided constructor arguments. If the object is of a type that itself uses allocators, or if it isstd::pair(until C++20), passes the inner allocator down to the constructed object.

      1) Constructs an object of typeT byuses-allocator construction at the uninitialized memory location indicated byp using the outermost allocator.

      Givenstd::uses_allocator<T, inner_allocator_type>::value asuses_inner:

      This overload participates in overload resolution only ifT is not a specialization ofstd::pair.

      (until C++20)

      Equivalent tostd::apply
      (
          [p, this](auto&&...newargs)
          {
              outermost-construct
                  (p,std::forward<decltype(newargs)>(newargs)...);
          },
          std::uses_allocator_construction_args
              (inner_allocator(),std::forward<Args>(args)...)
      );
      .

      (since C++20)
      2-6) Constructs astd::pair object byuses-allocator construction at the uninitialized memory location indicated byp using the outermost allocator.
      2) Letxprime beconcat-args <T1>(std::move(x)),yprime beconcat-args <T2>(std::move(y)), callsoutermost-construct (p,std::piecewise_construct, std::move(xprime), std::move(yprime)).
      3) Equivalent toconstruct(p,std::piecewise_construct,std::tuple<>(),std::tuple<>());.
      4-6) Equivalent toconstruct(p,std::piecewise_construct,
               std::forward_as_tuple(xarg),std::forward_as_tuple(yarg));
      , wherexarg andyarg are defined as follows:
       Overload xargyarg
      (4)std::forward<U>(x)std::forward<V>(y)
      (5)xy.firstxy.second
      (6)std::forward<U>(xy.first)std::forward<V>(xy.second)
      7) Merges the arguments contained intup and additional arguments required byuses-allocator construction of an object of typeT.
      Givenstd::uses_allocator<T, inner_allocator_type>::value asuses_inner:

      Contents

      [edit]Parameters

      p - pointer to allocated, but not initialized storage
      args - the constructor arguments to pass to the constructor ofT
      x - the constructor arguments to pass to the constructor ofT1
      y - the constructor arguments to pass to the constructor ofT2
      xy - the pair whose two members are the constructor arguments forT1 andT2
      tup - the arguments to be merged

      [edit]Notes

      This function is called (throughstd::allocator_traits) by any allocator-aware object, such asstd::vector, that was given astd::scoped_allocator_adaptor as the allocator to use. Sinceinner_allocator_type is itself a specialization ofstd::scoped_allocator_adaptor, this function will also be called when the allocator-aware objects constructed through this function start constructing their own members.

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      LWG 2203C++11inner allocators were obtained by value-initializing
      aninner_allocator_type object
      obtained by callinginner_allocator()
      LWG 2511
      (P0475R1)
      C++11concat-args might copy elements ofstd::tupleseliminated all element copy operations
      LWG 2586C++11only constructions from
      inner_allocator_type rvalues were checked
      checks constructions from non-const
      inner_allocator_type lvalues instead
      LWG 2975C++11overload(1) was not constrainedconstrained to refusestd::pair

      [edit]See also

      [static]
      constructs an object in the allocated storage
      (function template)[edit]
      (until C++20)
      constructs an object in allocated storage
      (public member function ofstd::allocator<T>)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/memory/scoped_allocator_adaptor/construct&oldid=177662"

      [8]ページ先頭

      ©2009-2025 Movatter.jp