string::string
Constructors.
Synopsis
string(); (1)
explicit
string(
storage_ptr sp); (2)
explicit
string(
std::size_t count,
char ch,
storage_ptr sp = {}); (3)
string(
string_view s,
storage_ptr sp = {}); (4)
string(
char const* s,
storage_ptr sp = {}); (5)
explicit
string(
char const* s,
std::size_t count,
storage_ptr sp = {}); (6)
template<
class InputIt>
explicit
string(
InputIt first,
InputIt last,
storage_ptr sp = {}); (7)
string(
string const& other); (8)
explicit
string(
string const& other,
storage_ptr sp); (9)
string(
string&& other) noexcept; (10)
explicit
string(
string&& other,
storage_ptr sp); (11)
string(
pilfered< string > other) noexcept; (12)
Description
Construct a string.
-
(1), (2) the string is empty with a non-zero, unspecified capacity.
-
(3) the string is filled with
count
copies of characterch
. -
(4) the string will contain a copy of the characters of
s
. -
(5) the string will contain a copy of the characters of the null-terminated string
s
. -
(6) the string will contain a copy of the characters in the range
[s, s + count)
. -
(7) the string will contain a copy of the characters in the range
[first, last)
. -
(8), (9) the string contains a copy of the characters of
other
. -
(10) the string acquires ownership of the contents of
other
. -
(11) equivalent to (10) if
*sp == *other.storage()
; otherwise equivalent to (9). -
(12) the string is 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)–(7), (9), (11) the constructed string uses memory resource of sp
. With (8), (10), and (12) it uses other
's memory resource. In either case the string will share the ownership of the memory resource. With (1) it uses the default memory resource.
After (10) other
behaves as if newly constructed with its current storage pointer.
After (12) other
is not in a usable state and may only be destroyed.
Constraints
InputIt
satisfies LegacyInputIterator.
Complexity
-
(1), (2), (10), (12) constant.
-
(3) linear in
count
. -
(4) linear in
s.size()
. -
(5) linear in
std::strlen(s)
. -
(6) linear in
count
. -
(7) linear in
std::distance(first, last)
. -
(8), (9) linear in
other.size()
. -
(11) constant if
*sp == *other.storage()
; otherwise linear inother.size()
.
Exception Safety
-
(1), (2), (10), (12) no-throw guarantee.
-
(3)–(6), (8), (9), (11) strong guarantee.
-
(7) strong guarantee if
InputIt
satisfies LegacyForwardIterator, basic guarantee otherwise.
Calls to memory_resource::allocate
may throw.
Template Parameters
Type | Description |
---|---|
|
The type of the iterators. |
Parameters
Name | Description |
---|---|
|
A pointer to the |
|
The size of the resulting string. |
|
The value to initialize characters of the string with. |
|
The string to copy from. |
|
An input iterator pointing to the first character to insert, or pointing to the end of the range. |
|
An input iterator pointing to the end of the range. |
|
The source string. |
Exceptions
Type | Thrown On |
---|---|
|
The constructed string’s size would have exceeded |