21 Strings library [strings]

21.4 Class template basic_string [basic.string]

21.4.2 basic_string constructors and assignment operators [string.cons]

explicit basic_string(const Allocator& a);

Effects: Constructs an object of class basic_string. The postconditions of this function are indicated in Table [tab:strings.ctr.1].

Table 63basic_string(const Allocator&) effects
ElementValue
data() a non-null pointer that is copyable and can have 0 added to it
size() 0
capacity() an unspecified value

basic_string(const basic_string& str); basic_string(basic_string&& str) noexcept;

Effects: Constructs an object of class basic_string as indicated in Table [tab:strings.ctr.cpy]. In the second form, str is left in a valid state with an unspecified value.

Table 64basic_string(const basic_string&) effects
ElementValue
data() points at the first element of an allocated copy of the array whose first element is pointed at by str.data()
size() str.size()
capacity() a value at least as large as size()

basic_string(const basic_string& str, size_type pos, size_type n = npos, const Allocator& a = Allocator());

Requires: pos <= str.size()

Throws: out_of_range if pos > str.size().

Effects: Constructs an object of class basic_string and determines the effective length rlen of the initial string value as the smaller of n and str.size() - pos, as indicated in Table [tab:strings.ctr.2].

Table 65basic_string(const basic_string&, size_type, size_type, const Allocator&) effects
ElementValue
data() points at the first element of an allocated copy of rlen consecutive elements of the string controlled by str beginning at position pos
size() rlen
capacity() a value at least as large as size()

basic_string(const charT* s, size_type n, const Allocator& a = Allocator());

Requires: s points to an array of at least n elements of charT.

Effects: Constructs an object of class basic_string and determines its initial string value from the array of charT of length n whose first element is designated by s, as indicated in Table [tab:strings.ctr.3].

Table 66basic_string(const charT*, size_type, const Allocator&) effects
ElementValue
data() points at the first element of an allocated copy of the array whose first element is pointed at by s
size() n
capacity() a value at least as large as size()

basic_string(const charT* s, const Allocator& a = Allocator());

Requires: s points to an array of at least traits::length(s) + 1 elements of charT.

Effects: Constructs an object of class basic_string and determines its initial string value from the array of charT of length traits::length(s) whose first element is designated by s, as indicated in Table [tab:strings.ctr.4].

Table 67basic_string(const charT*, const Allocator&) effects
ElementValue
data() points at the first element of an allocated copy of the array whose first element is pointed at by s
size() traits::length(s)
capacity() a value at least as large as size()

Remarks: Uses traits::length().

basic_string(size_type n, charT c, const Allocator& a = Allocator());

Requires: n < npos

Effects: Constructs an object of class basic_string and determines its initial string value by repeating the char-like object c for all n elements, as indicated in Table [tab:strings.ctr.5].

Table 68basic_string(size_t, charT, const Allocator&) effects
ElementValue
data() points at the first element of an allocated array of n elements, each storing the initial value c
size() n
capacity() a value at least as large as size()

template<class InputIterator> basic_string(InputIterator begin, InputIterator end, const Allocator& a = Allocator());

Effects: If InputIterator is an integral type, equivalent to

basic_string(static_cast<size_type>(begin), static_cast<value_type>(end), a)

Otherwise constructs a string from the values in the range [begin, end), as indicated in the Sequence Requirements table (see [sequence.reqmts]).

basic_string(initializer_list<charT> il, const Allocator& a = Allocator());

Effects: Same as basic_string(il.begin(), il.end(), a).

basic_string(const basic_string& str, const Allocator& alloc); basic_string(basic_string&& str, const Allocator& alloc);

Effects: Constructs an object of class basic_string as indicated in Table [tab:strings.ctr.6]. The stored allocator is constructed from alloc. In the second form, str is left in a valid state with an unspecified value.

Table 69basic_string(const basic_string&, const Allocator&) and basic_string(basic_string&&, const Allocator&) effects
ElementValue
data() points at the first element of an allocated copy of the array whose first element is pointed at by the original value of str.data().
size() the original value of str.size()
capacity() a value at least as large as size()
get_allocator() alloc

Throws: The second form throws nothing if alloc == str.get_allocator().

basic_string& operator=(const basic_string& str);

Effects: If *this and str are not the same object, modifies *this as shown in Table [tab:strings.op=].

If *this and str are the same object, the member has no effect.

Returns: *this

Table 70operator=(const basic_string&) effects
ElementValue
data() points at the first element of an allocated copy of the array whose first element is pointed at by str.data()
size() str.size()
capacity() a value at least as large as size()

basic_string& operator=(basic_string&& str) noexcept;

Effects: If *this and str are not the same object, modifies *this as shown in Table [tab:strings.op=rv]. [ Note: A valid implementation is swap(str).  — end note ]

If *this and str are the same object, the member has no effect.

Returns: *this

Table 71operator=(basic_string&&) effects
ElementValue
data() points at the array whose first element was pointed at by str.data()
size() previous value of str.size()
capacity() a value at least as large as size()

basic_string& operator=(const charT* s);

Returns: *this = basic_string(s).

Remarks: Uses traits::length().

basic_string& operator=(charT c);

Returns: *this = basic_string(1,c).

basic_string& operator=(initializer_list<charT> il);

Effects: *this = basic_string(il).

Returns: *this.