Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::pmr::polymorphic_allocator<T>::construct

      From cppreference.com
      <cpp‎ |memory‎ |polymorphic allocator
       
       
      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)
       
       
      template<class U,class...Args>
      void construct( U* p, Args&&...args);
      (1)(since C++17)
      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)(since C++17)
      (until C++20)
      template<class T1,class T2>
      void construct(std::pair<T1, T2>* p);
      (3)(since C++17)
      (until C++20)
      template<class T1,class T2,class U,class V>
      void construct(std::pair<T1, T2>* p, U&& x, V&& y);
      (4)(since C++17)
      (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)(since C++17)
      (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)(since C++17)
      (until C++20)
      template<class T1,class T2,class NonPair>
      void construct(std::pair<T1, T2>* p, NonPair&& non_pair);
      (7)(since C++17)
      (until C++20)

      Constructs an object in allocated, but not initialized storage pointed to byp the provided constructor arguments. If the object is of type that itself uses allocators, or if it is std::pair, passes*this down to the constructed object.

      1) Creates an object of the given typeU by means ofuses-allocator construction at the uninitialized memory location indicated byp, using*this as the allocator.This overload participates in overload resolution only ifU is not a specialization ofstd::pair.(until C++20)
      2) First, if eitherT1 orT2 is allocator-aware, modifies the tuplesx andy to includethis->resource(), resulting in the two new tuplesxprime andyprime, according to the following three rules:
      2a) ifT1 is not allocator-aware (std::uses_allocator<T1, polymorphic_allocator>::value==false) andstd::is_constructible<T1, Args1...>::value==true, thenxprime isx, unmodified.
      2b) ifT1 is allocator-aware (std::uses_allocator<T1, polymorphic_allocator>::value==true), and its constructor takes an allocator tag (std::is_constructible<T1,std::allocator_arg_t, polymorphic_allocator, Args1...>::value==true, thenxprime isstd::tuple_cat(std::make_tuple(std::allocator_arg,*this), std::move(x)).
      2c) ifT1 is allocator-aware (std::uses_allocator<T1, polymorphic_allocator>::value==true), and its constructor takes the allocator as the last argument (std::is_constructible<T1, Args1..., polymorphic_allocator>::value==true), thenxprime isstd::tuple_cat(std::move(x),std::make_tuple(*this)).
      2d) Otherwise, the program is ill-formed.
      Same rules apply toT2 and the replacement ofy withyprime.
      Oncexprime andyprime are constructed, constructs the pairp in allocated storage as if by::new((void*) p) pair<T1, T2>(std::piecewise_construct, std::move(xprime), std::move(yprime));.
      3) Equivalent toconstruct(p,std::piecewise_construct,std::tuple<>(),std::tuple<>()), that is, passes the memory resource on to the pair's member types if they accept them.
      5) Equivalent to
      6) Equivalent to
      7) This overload participates in overload resolution only if given the exposition-only function template
      template<class A,class B>void/*deduce-as-pair*/(conststd::pair<A, B>&);

      ,/*deduce-as-pair*/(non_pair) is ill-formed when considered as an unevaluated operand. Equivalent to

      construct<T1, T2, T1, T2>(p,std::forward<NonPair>(non_pair));
      (until C++20)

      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
      non_pair - non-pair argument to convert topair for further construction

      [edit]Return value

      (none)

      [edit]Notes

      This function is called (throughstd::allocator_traits) by any allocator-aware object, such asstd::pmr::vector (or anotherstd::vector that was given astd::pmr::polymorphic_allocator as the allocator to use).

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      LWG 2969C++17uses-allocator construction passedresource()passes*this
      LWG 2975C++17first overload is mistakenly used for pair construction in some casesconstrained to not accept pairs
      LWG 3525C++17no overload could handle non-pair types convertible topairreconstructing overload added

      [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/polymorphic_allocator/construct&oldid=160244"

      [8]ページ先頭

      ©2009-2025 Movatter.jp