Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::indirect<T, Allocator>::operator=

      From cppreference.com
      <cpp‎ |memory‎ |indirect
       
       
      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)
       
       
      constexpr indirect& operator=(const indirect& other);
      (1)(since C++26)
      constexpr indirect& operator=( indirect&& other)noexcept(/* see below */);
      (2)(since C++26)
      template<class U= T>
      constexpr indirect& operator=( U&& value);
      (3)(since C++26)

      Replaces contents of*this withvalue or the contents ofother.

      Lettraits bestd::allocator_traits<Allocator>:

      1) Ifstd::addressof(other)== this istrue, does nothing. Otherwise, letneed_update betraits::propagate_on_container_copy_assignment::value:
      • Ifother is valueless,*this becomes valueless and the object owned by*this (if any) is destroyed usingtraits::destroy and then the storage is deallocated.
      • Otherwise, ifalloc == other.alloc istrue and*this is not valueless, equivalent to**this=*other.
      • Otherwise:
      1. Constructs a new owned object in*this usingtraits::construct with*other as the argument, using the allocatorupdate_alloc? other.alloc : alloc.
      2. The previously owned object in*this (if any) is destroyed usingtraits::destroy and then the storage is deallocated.
      3. p points to the new owned object.
      After updating the object owned by*this, ifneed_update istrue,alloc is replaced with a copy ofother.alloc.
      Ifstd::is_copy_assignable_v<T>&&std::is_copy_constructible_v<T> isfalse, the program is ill-formed.
      2) Ifstd::addressof(other)== this istrue, does nothing. Otherwise, letneed_update betraits::propagate_on_container_move_assignment::value:
      • Ifother is valueless,*this becomes valueless and the object owned by*this (if any) is destroyed usingtraits::destroy and then the storage is deallocated.
      • Otherwise, ifalloc == other.alloc istrue, swaps the owned objects in*this andother; the owned object inother (if any) is then destroyed usingtraits::destroy and then the storage is deallocated.
      • Otherwise:
      1. Constructs a new owned object in*this usingtraits::construct withstd::move(*other) as the argument, using the allocatorupdate_alloc? other.alloc : alloc.
      2. The previously owned object in*this (if any) is destroyed usingtraits::destroy and then the storage is deallocated.
      3. p points to the new owned object.
      After updating the objects owned by*this andother, ifneed_update istrue,alloc is replaced with a copy ofother.alloc.
      Ifstd::is_copy_constructible_v<T> isfalse, the program is ill-formed.
      3) If*this is valueless, then constructs an owned object withstd::forward<U>(value) usingalloc . Otherwise, equivalent to**this=std::forward<U>(value).
      This overload participates in overload resolution only if all following conditions are satisfied:

      Contents

      [edit]Parameters

      other - anotherindirect object whose owned value (if exists) is used for assignment
      value - value to assign to or construct the owned value

      [edit]Return value

      *this

      [edit]Exceptions

      1) If any exception is thrown, the result ofthis->valueless_after_move() remains unchanged.
      If an exception is thrown during the call toT’s selected copy constructor, no effect.
      If an exception is thrown during the call toT’s copy assignment operator, the state ofthis->p is as defined by the exception safety guarantee ofT’s copy assignment operator.
      2) If any exception is thrown, there are no effects on*this orother.
      noexcept specification:  
      noexcept(std::allocator_traits<Allocator>::

                   propagate_on_container_move_assignment::value

                   ||std::allocator_traits<Allocator>::is_always_equal::value)

      [edit]Example

      This section is incomplete
      Reason: no example
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/memory/indirect/operator%3D&oldid=182599"

      [8]ページ先頭

      ©2009-2025 Movatter.jp