Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::polymorphic<T, Allocator>::polymorphic

      From cppreference.com
      <cpp‎ |memory‎ |polymorphic
       
       
      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)
       
       
      constexprexplicit polymorphic();
      (1)(since C++26)
      constexprexplicit polymorphic(std::allocator_arg_t,const Allocator& a);
      (2)(since C++26)
      template<class U= T>
      constexprexplicit polymorphic( U&& v);
      (3)(since C++26)
      template<class U= T>

      constexprexplicit polymorphic(std::allocator_arg_t,const Allocator& a,

                                      U&& v);
      (4)(since C++26)
      template<class U,class...Args>
      constexprexplicit polymorphic(std::in_place_type_t<U>, Args&&...args);
      (5)(since C++26)
      template<class U,class...Args>

      constexprexplicit polymorphic(std::allocator_arg_t,const Allocator& a,

                                     std::in_place_type_t<U>, Args&&...args);
      (6)(since C++26)
      template<class U,class I,class...Args>

      constexprexplicit polymorphic(std::in_place_type_t<U>,
                                     std::initializer_list<I> ilist,

                                      Args&&...args);
      (7)(since C++26)
      template<class U,class I,class...Args>

      constexprexplicit polymorphic(std::allocator_arg_t,const Allocator& a,
                                     std::in_place_type_t<U>,
                                     std::initializer_list<I> ilist,

                                      Args&&...args);
      (8)(since C++26)
      constexpr polymorphic(const polymorphic& other);
      (9)(since C++26)
      constexpr polymorphic(std::allocator_arg_t,const Allocator& a,
                             const polymorphic& other);
      (10)(since C++26)
      constexpr polymorphic( polymorphic&& other)noexcept;
      (11)(since C++26)
      constexpr polymorphic(std::allocator_arg_t,const Allocator& a,
                             polymorphic&& other)noexcept(/* see below */);
      (12)(since C++26)

      Constructs a newpolymorphic object.

      Contents

      [edit]Parameters

      a - the allocator to be associated
      v - value with which to initialize the owned value
      args - arguments with which to initialize the owned value
      il - initializer list with which to initialize the owned value
      other - anotherpolymorphic object whose owned value (if exists) is copied

      [edit]Effects

      The construction of a newpolymorphic object consists of the following steps:

      1) Constructs the associated allocatoralloc :
      2) Constructs the owned object:
      • For overloads(1-8), callsstd::allocator_traits<Allocator>::construct(alloc , p, args...), where
        • p is a pointer of typeU*, it points to storage suitable for the owned object to be constructed, and
        • args... is an expression pack containing the initializer arguments.
      • For overloads(9-12):
        • Ifother is valueless, no owned object is constructed, and*this is also valueless after construction.
        • Otherwise, ifother is an rvalue reference andalloc equalsother.alloc,*this takes ownership of the owned object ofother.
        • Otherwise, the owned object is constructed usingalloc as described above, where the type ofp is determined by the type of the object owned byother.
       Overload Initializer for...Type of the owned objectvalueless_after_move()
      after construction
      allocthe owned object
      (1)(empty)(empty)Tfalse
      (2)a
      (3)(empty)std::forward<U>(v)U
      (4)a
      (5)(empty)std::forward<Args>(args)
      (6)a
      (7)(empty)ilist,                  
      std::forward<Args>(args)
      (8)a
      (9) see below *other
      (only ifother owns a value)
      the type of the object owned byothertrue only ifother is valueless
      (10)a
      (11)std::move         
          (other.alloc )
      takes ownership
      (only ifother owns a value)
      (12)asee below
      9)alloc is direct-non-list-initialized withstd::allocator_traits<Allocator>::
          select_on_container_copy_construction(other.alloc )
      .
      12) The owned object is constructed as follows:
      • Ifother is valueless,*this is also valueless.
      • Otherwise, ifalloc== other.alloc istrue,*this takes ownership of the owned object ofother.
      • Otherwise, constructs an owned object with*std::move(other) usingalloc .

      [edit]Constraints and supplement information

      1,2) If any of the following values isfalse, the program is ill-formed:

      1) This overload participates in overload resolution only ifstd::is_default_constructible_v<Allocator> istrue.

      3-8) These overloads participate in overload resolution only if the following values are alltrue:
      3,4)U
      5,6)Args...
      7,8)std::initializer_list<I>&, Args...

      3,5,7) These overloads participate in overload resolution only ifstd::is_default_constructible_v<Allocator> istrue.
      3,4) These overloads participate in overload resolution only if all following conditions are satisfied:
      5-8) These overloads participate in overload resolution only ifstd::is_same_v<std::remove_cvref_t<U>, U> istrue.

      [edit]Exceptions

      Throws nothing unlessstd::allocator_traits<Allocator>::allocate orstd::allocator_traits<Allocator>::construct throws.

      12)
      noexcept specification:  
      noexcept(std::allocator_traits<Allocator>::is_always_equal::value)

      [edit]Example

      This section is incomplete
      Reason: no example

      [edit]See also

      tag type used to select allocator-aware constructor overloads
      (class)[edit]
      in-place construction tag
      (tag)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/memory/polymorphic/polymorphic&oldid=182596"

      [8]ページ先頭

      ©2009-2026 Movatter.jp