value::value
Constructors.
Synopsis
value() noexcept; (1)
explicit
value(
storage_ptr sp) noexcept; (2)
value(
std::nullptr_t,
storage_ptr sp = {}) noexcept; (3)
value(
bool b,
storage_ptr sp = {}) noexcept; (4)
value(
signed char i,
storage_ptr sp = {}) noexcept; (5)
value(
short i,
storage_ptr sp = {}) noexcept; (6)
value(
int i,
storage_ptr sp = {}) noexcept; (7)
value(
long i,
storage_ptr sp = {}) noexcept; (8)
value(
long long i,
storage_ptr sp = {}) noexcept; (9)
value(
unsigned char u,
storage_ptr sp = {}) noexcept; (10)
value(
unsigned short u,
storage_ptr sp = {}) noexcept; (11)
value(
unsigned int u,
storage_ptr sp = {}) noexcept; (12)
value(
unsigned long u,
storage_ptr sp = {}) noexcept; (13)
value(
unsigned long long u,
storage_ptr sp = {}) noexcept; (14)
value(
double d,
storage_ptr sp = {}) noexcept; (15)
value(
string_view s,
storage_ptr sp = {}); (16)
value(
char const* s,
storage_ptr sp = {}); (17)
value(
string s) noexcept; (18)
value(
string const& s,
storage_ptr sp); (19)
value(
string&& s,
storage_ptr sp); (20)
value(
string_kind_t,
storage_ptr sp = {}) noexcept; (21)
value(
array arr) noexcept; (22)
value(
array const& arr,
storage_ptr sp); (23)
value(
array&& arr,
storage_ptr sp); (24)
value(
array_kind_t,
storage_ptr sp = {}) noexcept; (25)
value(
object obj) noexcept; (26)
value(
object const& obj,
storage_ptr sp); (27)
value(
object&& obj,
storage_ptr sp); (28)
value(
object_kind_t,
storage_ptr sp = {}) noexcept; (29)
value(
std::initializer_list< value_ref > init,
storage_ptr sp = {}); (30)
value(
value const& other); (31)
value(
value const& other,
storage_ptr sp); (32)
value(
value&& other) noexcept; (33)
value(
value&& other,
storage_ptr sp); (34)
value(
pilfered< value > other) noexcept; (35)
Description
Construct a new value
.
-
(1)–(3) the constructed value is null.
-
(4) the constructed value contains a copy of
b
. -
(5)–(9) the constructed value contains a copy of
i
. -
(10)–(14) the constructed value contains a copy of
u
. -
(15) the constructed value contains a copy of
d
. -
(16), (19) the constructed value contains a copy of the string
s
. -
(17) the constructed value contains a copy of the null-terminated string
s
. -
(18) the constructed value takes ownership of
s
's storage. -
(20) if
*s.storage() == *sp
equivalent to (18), otherwise equivalent to (19). -
(21) the constructed value contains an empty string.
-
(22) the constructed value takes ownership of
arr
's storage. -
(23) the constructed value contains an element-wise copy of the array
arr
. -
(24) if
*arr.storage() == *sp
equivalent to (22), otherwise equivalent to (23). -
(25) the constructed value contains an empty array.
-
(26) the constructed value takes ownership of
obj
's storage. -
(27) the constructed value contains an element-wise copy of the object
obj
. -
(28) if
*obj.storage() == *sp
equivalent to (26), otherwise equivalent to (27). -
(29) the constructed value contains an empty object.
-
(30) the constructed value’s contents are formed by constructing from
init
andsp
(see Initializer Lists). -
(31), (32) the constructed value contains a copy of the contents of
other
. -
(33) the constructed value acquires ownership of the contents of
other
. -
(34) equivalent to (33) if
*sp == *other.storage()
; otherwise equivalent to (32). -
(35) the constructed value acquires ownership of the contents of
other
using pilfer semantics. This is more efficient than move construction, when it is known that the moved-from object will be immediately destroyed afterwards.
With (2)–(17), (19)–(21), (23)–(25), (27)–(30), (32), and (34) the constructed value uses memory resource of sp
. With (18), (22), (26), (31), (33), and (35) it uses the memory resource of the argument (s
, arr
, obj, or
value`). In either case the value will share the ownership of the memory resource. With (1) it uses the default memory resource.
After (18), (22), (26), and (33) the argument behaves as if newly constructed with its current storage pointer (i.e. becomes an empty string, array, object, or null value).
After (35) other
is not in a usable state and may only be destroyed.
Complexity
-
(1)–(15), (18), (21), (22), (25), (26), (29), (33), (35) constant.
-
(16), (19) linear in
s.size()
. -
(17) linear in
std::strlen(s)
. -
(20) if
*s.storage() == *sp
constant, otherwise linear ins.size()
. -
(23) linear in
arr.size()
. -
(24) if
*arr.storage() == *sp
constant, otherwise linear inarr.size()
. -
(27) linear in
obj.size()
. -
(28) if
*obj.storage() == *sp
constant, otherwise linear inobj.size()
. -
(30) linear in
init.size()
. -
(31), (32) linear in the size of
other
. -
(34) constant if
*sp == *other.storage()
; otherwise linear in the size ofother
.
The size of other
is either the size of the underlying container (if there is one), or can be considered to be 1.
Exception Safety
-
(1)–(15), (18), (21), (22), (25), (26), (29), (33), (35)** no-throw guarantee.
-
(16), (17), (19), (23), (27), (30)–(32)** strong guarantee.
-
(20) if
*s.storage() == *sp
no-throw guarantee, otherwise strong guarantee. -
(24) if
*arr.storage() == *sp
no-throw guarantee, otherwise strong guarantee. -
(28) if
*obj.storage() == *sp
no-throw guarantee, otherwise strong guarantee. -
(33) if
*other.storage() == *sp
no-throw guarantee, otherwise strong guarantee.
Calls to memory_resource::allocate
may throw.
Parameters
Name | Description |
---|---|
|
A pointer to the |
|
The boolean to construct with. |
|
The number to construct with. |
|
The number to construct with. |
|
The number to construct with. |
|
The string to construct with. |
|
The array to construct with. |
|
The object to construct with. |
|
The initializer list to construct from. |
|
Another |