value::operator=
Assignment.
Synopsis
value&
operator=(
value const& other); (1)
value&
operator=(
value&& other); (2)
value&
operator=(
std::initializer_list< value_ref > init); (3)
value&
operator=(
std::nullptr_t) noexcept; (4)
value&
operator=(
bool b) noexcept; (5)
value&
operator=(
signed char i) noexcept; (6)
value&
operator=(
short i) noexcept; (7)
value&
operator=(
int i) noexcept; (8)
value&
operator=(
long i) noexcept; (9)
value&
operator=(
long long i) noexcept; (10)
value&
operator=(
unsigned char u) noexcept; (11)
value&
operator=(
unsigned short u) noexcept; (12)
value&
operator=(
unsigned int u) noexcept; (13)
value&
operator=(
unsigned long u) noexcept; (14)
value&
operator=(
unsigned long long u) noexcept; (15)
value&
operator=(
double d) noexcept; (16)
value&
operator=(
string_view s); (17)
value&
operator=(
char const* s); (18)
value&
operator=(
string const& s); (19)
value&
operator=(
string&& s); (20)
value&
operator=(
array const& arr); (21)
value&
operator=(
array&& arr); (22)
value&
operator=(
object const& obj); (23)
value&
operator=(
object&& obj); (24)
Description
Replaces the contents of this value.
-
(1) replaces with an element-wise copy of the contents of
other. -
(2) replaces with the contents
otherusing move semantics (see below). -
(3) replaces with the value formed by constructing from
initandthis->storage()(see Initializer Lists). -
(4) replaces with null.
-
(5) replaces with the boolean value
b. -
(6)–(10) replaces with the signed integer
i. -
(11)–(15) replaces with the unsigned integer
u. -
(16) replaces with the number
d. -
(17), (19) replaces with a copy of the string
s. -
(18), equivalent to
*this = string_view(s). -
(20) replaces with the string
susing move semantics see below. -
(21) replaces with a copy of the array
arr. -
(22) replaces with the array
arrusing move semantics (see below). -
(23) replaces with a copy of the object
obj. -
(24) replaces with the object
objusing move semantics (see below).
Move assignment for value never changes the associated memory resource. Because of this if the memory resource of the assigned value differs from that of *this, the operation is equivalent to a copy. Otherwise, it replaces the underlying storage in constant time without the possibility of exceptions.
Complexity
-
(1) linear in the sizes of
*thisandother. -
(2) constant if
*this->storage() == *other.storage(), otherwise linear in the sizes of*thisandother. -
(3) linear in the sizes of
*thisandinit. -
(4)–(16) linear in the size of
*this. -
(17), (19) linear in the size of
*thisands.size(). -
(18) linear in the size of
*thisandstd::strlen(s). -
(22) constant if
*this->storage() == *s.storage(), otherwise linear in the size of*thisands.size(). -
(21) linear in the size of
*thisandarr.size(). -
(22) constant if
*this->storage() == *arr.storage(), otherwise linear in the size of*thisandarr.size(). -
(23) linear in the size of
*thisandobj.size(). -
(24) constant if
*this->storage() == *obj.storage(), otherwise linear in the size of*thisandobj.size().
The size of *this is either the size of the underlying container (if there is one), or can be considered to be 1.
Exception Safety
-
(1)–(3), (17)–(24) strong guarantee.
-
(4)–(16) no-throw guarantee.
Calls to memory_resource::allocate may throw.
Parameters
| Name | Description |
|---|---|
|
The source value. |
|
The initializer list to assign from. |
|
The new value. |
|
The new value. |
|
The new value. |
|
The new value. |
|
The new string. |
|
The new array. |
|
The new object. |