21 Strings library [strings]

21.3 String classes [string.classes]

21.3.3 Class template basic_­string [basic.string]

21.3.3.3 Constructors and assignment operators [string.cons]

constexpr explicit basic_string(const Allocator& a) noexcept;
Postconditions: size() is equal to 0.
constexpr basic_string(const basic_string& str); constexpr basic_string(basic_string&& str) noexcept;
Effects: Constructs an object whose value is that of str prior to this call.
Remarks: In the second form, str is left in a valid but unspecified state.
constexpr basic_string(const basic_string& str, size_type pos, const Allocator& a = Allocator()); constexpr basic_string(const basic_string& str, size_type pos, size_type n, const Allocator& a = Allocator());
Effects: Let n be npos for the first overload.
Equivalent to: basic_string(basic_string_view<charT, traits>(str).substr(pos, n), a)
template<class T> constexpr basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator());
Constraints: is_­convertible_­v<const T&, basic_­string_­view<charT, traits>> is true.
Effects: Creates a variable, sv, as if by basic_­string_­view<charT, traits> sv = t; and then behaves the same as: basic_string(sv.substr(pos, n), a);
template<class T> constexpr explicit basic_string(const T& t, const Allocator& a = Allocator());
Constraints:
  • is_­convertible_­v<const T&, basic_­string_­view<charT, traits>> is true and
  • is_­convertible_­v<const T&, const charT*> is false.
Effects: Creates a variable, sv, as if by basic_­string_­view<charT, traits> sv = t; and then behaves the same as basic_­string(sv.data(), sv.size(), a).
constexpr basic_string(const charT* s, size_type n, const Allocator& a = Allocator());
Preconditions: [s, s + n) is a valid range.
Effects: Constructs an object whose initial value is the range [s, s + n).
Postconditions: size() is equal to n, and traits​::​compare(data(), s, n) is equal to 0.
constexpr basic_string(const charT* s, const Allocator& a = Allocator());
Constraints: Allocator is a type that qualifies as an allocator ([container.requirements.general]).
[Note 1:
This affects class template argument deduction.
— end note]
Effects: Equivalent to: basic_­string(s, traits​::​length(s), a).
constexpr basic_string(size_type n, charT c, const Allocator& a = Allocator());
Constraints: Allocator is a type that qualifies as an allocator ([container.requirements.general]).
[Note 2:
This affects class template argument deduction.
— end note]
Effects: Constructs an object whose value consists of n copies of c.
template<class InputIterator> constexpr basic_string(InputIterator begin, InputIterator end, const Allocator& a = Allocator());
Constraints: InputIterator is a type that qualifies as an input iterator ([container.requirements.general]).
Effects: Constructs a string from the values in the range [begin, end), as indicated in Table 77.
constexpr basic_string(initializer_list<charT> il, const Allocator& a = Allocator());
Effects: Equivalent to basic_­string(il.begin(), il.end(), a).
constexpr basic_string(const basic_string& str, const Allocator& alloc); constexpr basic_string(basic_string&& str, const Allocator& alloc);
Effects: Constructs an object whose value is that of str prior to this call.
The stored allocator is constructed from alloc.
In the second form, str is left in a valid but unspecified state.
Throws: The second form throws nothing if alloc == str.get_­allocator().
template<class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> basic_string(InputIterator, InputIterator, Allocator = Allocator()) -> basic_string<typename iterator_traits<InputIterator>::value_type, char_traits<typename iterator_traits<InputIterator>::value_type>, Allocator>;
Constraints: InputIterator is a type that qualifies as an input iterator, and Allocator is a type that qualifies as an allocator ([container.requirements.general]).
template<class charT, class traits, class Allocator = allocator<charT>> explicit basic_string(basic_string_view<charT, traits>, const Allocator& = Allocator()) -> basic_string<charT, traits, Allocator>; template<class charT, class traits, class Allocator = allocator<charT>> basic_string(basic_string_view<charT, traits>, typename see below::size_type, typename see below::size_type, const Allocator& = Allocator()) -> basic_string<charT, traits, Allocator>;
Constraints: Allocator is a type that qualifies as an allocator ([container.requirements.general]).
constexpr basic_string& operator=(const basic_string& str);
Effects: If *this and str are the same object, has no effect.
Otherwise, replaces the value of *this with a copy of str.
Returns: *this.
constexpr basic_string& operator=(basic_string&& str) noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value || allocator_traits<Allocator>::is_always_equal::value);
Effects: Move assigns as a sequence container, except that iterators, pointers and references may be invalidated.
Returns: *this.
template<class T> constexpr basic_string& operator=(const T& t);
Constraints:
  • is_­convertible_­v<const T&, basic_­string_­view<charT, traits>> is true and
  • is_­convertible_­v<const T&, const charT*> is false.
Effects: Equivalent to: basic_string_view<charT, traits> sv = t; return assign(sv);
constexpr basic_string& operator=(const charT* s);
Effects: Equivalent to: return *this = basic_­string_­view<charT, traits>(s);
constexpr basic_string& operator=(charT c);
Effects: Equivalent to: return *this = basic_string_view<charT, traits>(addressof(c), 1);
constexpr basic_string& operator=(initializer_list<charT> il);
Effects: Equivalent to: return *this = basic_string_view<charT, traits>(il.begin(), il.size());