[string.cons] (original) (raw)

27 Strings library [strings]

27.4 String classes [string.classes]

27.4.3 Class template basic_string [basic.string]

27.4.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());constexpr basic_string(basic_string&& str, size_type pos,const Allocator& a = Allocator());constexpr basic_string(basic_string&& str, size_type pos, size_type n,const Allocator& a = Allocator());

Let

Effects: Constructs an object whose initial value is the range [s.data() + pos, s.data() + rlen).

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

Remarks: For the overloads with a basic_string&& parameter,str is left in a valid but unspecified state.

Recommended practice: For the overloads with a basic_string&& parameter, implementations should avoid allocation if s.get_allocator() == a is true.

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:

Effects: Creates a variable, sv, as if bybasic_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, andtraits​::​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.reqmts]).

[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.reqmts]).

[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.reqmts]).

Effects: Constructs a string from the values in the range [begin, end), as specified in [sequence.reqmts].

Effects: Constructs a string from the values in the range rg, as specified in [sequence.reqmts].

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.reqmts]).

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>;

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.

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 ([sequence.reqmts]), except that iterators, pointers and references may be invalidated.

template<class T> constexpr basic_string& operator=(const T& t);

Constraints:

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());