Files
cppdraft_translate/cppdraft/basic/string.md
2025-10-25 03:02:53 +03:00

97 KiB
Raw Blame History

[basic.string]

27 Strings library [strings]

27.4 String classes [string.classes]

27.4.3 Class template basic_string [basic.string]

27.4.3.1 General [basic.string.general]

1

#

The class templatebasic_string describes objects that can store a sequence consisting of a varying number of arbitrary char-like objects with the first element of the sequence at position zero.

Such a sequence is also called a “string” if the type of the char-like objects that it holds is clear from context.

In the rest of [basic.string], the type of the char-like objects held in a basic_string object is designated by charT.

2

#

A specialization of basic_string is a contiguous container ([container.reqmts]).

3

#

In all cases, [data(), data() + size()] is a valid range,data() + size() points at an object with value charT() (a “null terminator”), and size() <= capacity() is true.

🔗

namespace std {template<class charT, class traits = char_traits, class Allocator = allocator>class basic_string {public:// typesusing traits_type = traits; using value_type = charT; using allocator_type = Allocator; using size_type = typename allocator_traits::size_type; using difference_type = typename allocator_traits::difference_type; using pointer = typename allocator_traits::pointer; using const_pointer = typename allocator_traits::const_pointer; using reference = value_type&; using const_reference = const value_type&; using iterator = implementation-defined; // see [container.requirements]using const_iterator = implementation-defined; // see [container.requirements]using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::reverse_iterator<const_iterator>; static constexpr size_type npos = size_type(-1); // [string.cons], construct/copy/destroyconstexpr basic_string() noexcept(noexcept(Allocator())) : basic_string(Allocator()) { }constexpr explicit basic_string(const Allocator& a) noexcept; constexpr basic_string(const basic_string& str); constexpr basic_string(basic_string&& str) noexcept; 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()); templateconstexpr basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); templateconstexpr explicit basic_string(const T& t, const Allocator& a = Allocator()); constexpr basic_string(const charT* s, size_type n, const Allocator& a = Allocator()); constexpr basic_string(const charT* s, const Allocator& a = Allocator()); basic_string(nullptr_t) = delete; constexpr basic_string(size_type n, charT c, const Allocator& a = Allocator()); templateconstexpr basic_string(InputIterator begin, InputIterator end, const Allocator& a = Allocator()); template<container-compatible-range R>constexpr basic_string(from_range_t, R&& rg, const Allocator& a = Allocator()); constexpr basic_string(initializer_list, const Allocator& = Allocator()); constexpr basic_string(const basic_string&, const Allocator&); constexpr basic_string(basic_string&&, const Allocator&); constexpr ~basic_string(); constexpr basic_string& operator=(const basic_string& str); constexpr basic_string& operator=(basic_string&& str)noexcept(allocator_traits::propagate_on_container_move_assignment::value || allocator_traits::is_always_equal::value); templateconstexpr basic_string& operator=(const T& t); constexpr basic_string& operator=(const charT* s); basic_string& operator=(nullptr_t) = delete; constexpr basic_string& operator=(charT c); constexpr basic_string& operator=(initializer_list); // [string.iterators], iteratorsconstexpr iterator begin() noexcept; constexpr const_iterator begin() const noexcept; constexpr iterator end() noexcept; constexpr const_iterator end() const noexcept; constexpr reverse_iterator rbegin() noexcept; constexpr const_reverse_iterator rbegin() const noexcept; constexpr reverse_iterator rend() noexcept; constexpr const_reverse_iterator rend() const noexcept; constexpr const_iterator cbegin() const noexcept; constexpr const_iterator cend() const noexcept; constexpr const_reverse_iterator crbegin() const noexcept; constexpr const_reverse_iterator crend() const noexcept; // [string.capacity], capacityconstexpr size_type size() const noexcept; constexpr size_type length() const noexcept; constexpr size_type max_size() const noexcept; constexpr void resize(size_type n, charT c); constexpr void resize(size_type n); template constexpr void resize_and_overwrite(size_type n, Operation op); constexpr size_type capacity() const noexcept; constexpr void reserve(size_type res_arg); constexpr void shrink_to_fit(); constexpr void clear() noexcept; constexpr bool empty() const noexcept; // [string.access], element accessconstexpr const_reference operator[](size_type pos) const; constexpr reference operator[](size_type pos); constexpr const_reference at(size_type n) const; constexpr reference at(size_type n); constexpr const charT& front() const; constexpr charT& front(); constexpr const charT& back() const; constexpr charT& back(); // [string.modifiers], modifiersconstexpr basic_string& operator+=(const basic_string& str); templateconstexpr basic_string& operator+=(const T& t); constexpr basic_string& operator+=(const charT* s); constexpr basic_string& operator+=(charT c); constexpr basic_string& operator+=(initializer_list); constexpr basic_string& append(const basic_string& str); constexpr basic_string& append(const basic_string& str, size_type pos, size_type n = npos); templateconstexpr basic_string& append(const T& t); templateconstexpr basic_string& append(const T& t, size_type pos, size_type n = npos); constexpr basic_string& append(const charT* s, size_type n); constexpr basic_string& append(const charT* s); constexpr basic_string& append(size_type n, charT c); templateconstexpr basic_string& append(InputIterator first, InputIterator last); template<container-compatible-range R>constexpr basic_string& append_range(R&& rg); constexpr basic_string& append(initializer_list); constexpr void push_back(charT c); constexpr basic_string& assign(const basic_string& str); constexpr basic_string& assign(basic_string&& str)noexcept(allocator_traits::propagate_on_container_move_assignment::value || allocator_traits::is_always_equal::value); constexpr basic_string& assign(const basic_string& str, size_type pos, size_type n = npos); templateconstexpr basic_string& assign(const T& t); templateconstexpr basic_string& assign(const T& t, size_type pos, size_type n = npos); constexpr basic_string& assign(const charT* s, size_type n); constexpr basic_string& assign(const charT* s); constexpr basic_string& assign(size_type n, charT c); templateconstexpr basic_string& assign(InputIterator first, InputIterator last); template<container-compatible-range R>constexpr basic_string& assign_range(R&& rg); constexpr basic_string& assign(initializer_list); constexpr basic_string& insert(size_type pos, const basic_string& str); constexpr basic_string& insert(size_type pos1, const basic_string& str, size_type pos2, size_type n = npos); templateconstexpr basic_string& insert(size_type pos, const T& t); templateconstexpr basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n = npos); constexpr basic_string& insert(size_type pos, const charT* s, size_type n); constexpr basic_string& insert(size_type pos, const charT* s); constexpr basic_string& insert(size_type pos, size_type n, charT c); constexpr iterator insert(const_iterator p, charT c); constexpr iterator insert(const_iterator p, size_type n, charT c); templateconstexpr iterator insert(const_iterator p, InputIterator first, InputIterator last); template<container-compatible-range R>constexpr iterator insert_range(const_iterator p, R&& rg); constexpr iterator insert(const_iterator p, initializer_list); constexpr basic_string& erase(size_type pos = 0, size_type n = npos); constexpr iterator erase(const_iterator p); constexpr iterator erase(const_iterator first, const_iterator last); constexpr void pop_back(); constexpr basic_string& replace(size_type pos1, size_type n1, const basic_string& str); constexpr basic_string& replace(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2 = npos); templateconstexpr basic_string& replace(size_type pos1, size_type n1, const T& t); templateconstexpr basic_string& replace(size_type pos1, size_type n1, const T& t, size_type pos2, size_type n2 = npos); constexpr basic_string& replace(size_type pos, size_type n1, const charT* s, size_type n2); constexpr basic_string& replace(size_type pos, size_type n1, const charT* s); constexpr basic_string& replace(size_type pos, size_type n1, size_type n2, charT c); constexpr basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str); templateconstexpr basic_string& replace(const_iterator i1, const_iterator i2, const T& t); constexpr basic_string& replace(const_iterator i1, const_iterator i2, const charT* s, size_type n); constexpr basic_string& replace(const_iterator i1, const_iterator i2, const charT* s); constexpr basic_string& replace(const_iterator i1, const_iterator i2, size_type n, charT c); templateconstexpr basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2); template<container-compatible-range R>constexpr basic_string& replace_with_range(const_iterator i1, const_iterator i2, R&& rg); constexpr basic_string& replace(const_iterator, const_iterator, initializer_list); constexpr size_type copy(charT* s, size_type n, size_type pos = 0) const; constexpr void swap(basic_string& str)noexcept(allocator_traits::propagate_on_container_swap::value || allocator_traits::is_always_equal::value); // [string.ops], string operationsconstexpr const charT* c_str() const noexcept; constexpr const charT* data() const noexcept; constexpr charT* data() noexcept; constexpr operator basic_string_view<charT, traits>() const noexcept; constexpr allocator_type get_allocator() const noexcept; templateconstexpr size_type find(const T& t, size_type pos = 0) const noexcept(see below); constexpr size_type find(const basic_string& str, size_type pos = 0) const noexcept; constexpr size_type find(const charT* s, size_type pos, size_type n) const; constexpr size_type find(const charT* s, size_type pos = 0) const; constexpr size_type find(charT c, size_type pos = 0) const noexcept; templateconstexpr size_type rfind(const T& t, size_type pos = npos) const noexcept(see below); constexpr size_type rfind(const basic_string& str, size_type pos = npos) const noexcept; constexpr size_type rfind(const charT* s, size_type pos, size_type n) const; constexpr size_type rfind(const charT* s, size_type pos = npos) const; constexpr size_type rfind(charT c, size_type pos = npos) const noexcept; templateconstexpr size_type find_first_of(const T& t, size_type pos = 0) const noexcept(see below); constexpr size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept; constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const; constexpr size_type find_first_of(const charT* s, size_type pos = 0) const; constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept; templateconstexpr size_type find_last_of(const T& t, size_type pos = npos) const noexcept(see below); constexpr size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept; constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const; constexpr size_type find_last_of(const charT* s, size_type pos = npos) const; constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept; templateconstexpr size_type find_first_not_of(const T& t, size_type pos = 0) const noexcept(see below); constexpr size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept; constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const; constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const; constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept; templateconstexpr size_type find_last_not_of(const T& t, size_type pos = npos) const noexcept(see below); constexpr size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept; constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const; constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const; constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept; constexpr basic_string substr(size_type pos = 0, size_type n = npos) const &; constexpr basic_string substr(size_type pos = 0, size_type n = npos) &&; constexpr basic_string_view<charT, traits> subview(size_type pos = 0, size_type n = npos) const; templateconstexpr int compare(const T& t) const noexcept(see below); templateconstexpr int compare(size_type pos1, size_type n1, const T& t) const; templateconstexpr int compare(size_type pos1, size_type n1, const T& t, size_type pos2, size_type n2 = npos) const; constexpr int compare(const basic_string& str) const noexcept; constexpr int compare(size_type pos1, size_type n1, const basic_string& str) const; constexpr int compare(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2 = npos) const; constexpr int compare(const charT* s) const; constexpr int compare(size_type pos1, size_type n1, const charT* s) const; constexpr int compare(size_type pos1, size_type n1, const charT* s, size_type n2) const; constexpr bool starts_with(basic_string_view<charT, traits> x) const noexcept; constexpr bool starts_with(charT x) const noexcept; constexpr bool starts_with(const charT* x) const; constexpr bool ends_with(basic_string_view<charT, traits> x) const noexcept; constexpr bool ends_with(charT x) const noexcept; constexpr bool ends_with(const charT* x) const; constexpr bool contains(basic_string_view<charT, traits> x) const noexcept; constexpr bool contains(charT x) const noexcept; constexpr bool contains(const charT* x) const; }; template<class InputIterator, class Allocator = allocator<typename iterator_traits::value_type>> basic_string(InputIterator, InputIterator, Allocator = Allocator())-> basic_string<typename iterator_traits::value_type, char_traits<typename iterator_traits::value_type>, Allocator>; template<ranges::input_range R, class Allocator = allocator<ranges::range_value_t>> basic_string(from_range_t, R&&, Allocator = Allocator())-> basic_string<ranges::range_value_t, char_traits<ranges::range_value_t>, Allocator>; template<class charT, class traits, class Allocator = allocator>explicit basic_string(basic_string_view<charT, traits>, const Allocator& = Allocator())-> basic_string<charT, traits, Allocator>; template<class charT, class traits, class Allocator = allocator> 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>;}

4

#

A size_type parameter type in a basic_string deduction guide refers to the size_type member type of the type deduced by the deduction guide.

5

#

The types iterator and const_iterator meet the constexpr iterator requirements ([iterator.requirements.general]).

27.4.3.2 General requirements [string.require]

1

#

If any operation would cause size() to exceed max_size(), that operation throws an exception object of type length_error.

2

#

If any member function or operator of basic_string throws an exception, that function or operator has no other effect on the basic_string object.

3

#

Every object of typebasic_string<charT, traits, Allocator> uses an object of typeAllocator to allocate and free storage for the contained charT objects as needed.

The Allocator object used is obtained as described in [container.reqmts].

In every specialization basic_string<charT, traits, Allocator>, the type traits shall meet the character traits requirements ([char.traits]).

[Note 1:

Every specialization basic_string<charT, traits, Allocator> is an allocator-aware container ([container.alloc.reqmts]), but does not use the allocator's construct and destroy member functions ([container.requirements.pre]).

The program is ill-formed ifAllocator::value_type is not the same type as charT.

— end note]

[Note 2:

The program is ill-formed if traits::char_type is not the same type as charT.

— end note]

4

#

References, pointers, and iterators referring to the elements of abasic_string sequence may be invalidated by the following uses of that basic_string object:

  • (4.1)

    Passing as an argument to any standard library function taking a reference to non-constbasic_string as an argument.212

  • (4.2)

    Calling non-const member functions, exceptoperator[],at,data,front,back,begin,rbegin,end, andrend.

212)212)

For example, as an argument to non-member functions swap() ([string.special]),operator>>() ([string.io]), and getline() ([string.io]), or as an argument to basic_string::swap().

27.4.3.3 Constructors and assignment operators [string.cons]

🔗

constexpr explicit basic_string(const Allocator& a) noexcept;

1

#

Postconditions: size() is equal to 0.

🔗

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

2

#

Effects: Constructs an object whose value is that of str prior to this call.

3

#

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

4

#

Let

s be the value of str prior to this call and

rlen be pos + min(n, s.size() - pos) for the overloads with parameter n, ands.size() otherwise.

5

#

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

6

#

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

7

#

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

8

#

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

9

#

Constraints: is_convertible_v<const T&, basic_string_view<charT, traits>> is true.

10

#

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

11

#

Constraints:

is_convertible_v<const T&, basic_string_view<charT, traits>> istrue and

is_convertible_v<const T&, const charT*> isfalse.

12

#

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

13

#

Preconditions: [s, s + n) is a valid range.

14

#

Effects: Constructs an object whose initial value is the range [s, s + n).

15

#

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

16

#

Constraints: Allocator is a type that qualifies as an allocator ([container.reqmts]).

[Note 1:

This affects class template argument deduction.

— end note]

17

#

Effects: Equivalent to: basic_string(s, traits::length(s), a).

🔗

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

18

#

Constraints: Allocator is a type that qualifies as an allocator ([container.reqmts]).

[Note 2:

This affects class template argument deduction.

— end note]

19

#

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

20

#

Constraints: InputIterator is a type that qualifies as an input iterator ([container.reqmts]).

21

#

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

🔗

template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<charT> R> constexpr basic_string(from_range_t, R&& rg, const Allocator& = Allocator());

22

#

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

23

#

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

24

#

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.

25

#

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

26

#

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> explicit basic_string(basic_string_view<charT, traits>, const Allocator& = Allocator()) -> basic_string<charT, traits, Allocator>;

template<class charT, class traits, class Allocator = allocator> 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>; `

27

#

Constraints: Allocator is a type that qualifies as an allocator ([container.reqmts]).

🔗

constexpr basic_string& operator=(const basic_string& str);

28

#

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

Otherwise, replaces the value of *this with a copy of str.

29

#

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

30

#

Effects: Move assigns as a sequence container ([sequence.reqmts]), except that iterators, pointers and references may be invalidated.

31

#

Returns: *this.

🔗

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

32

#

Constraints:

is_convertible_v<const T&, basic_string_view<charT, traits>> is true and

is_convertible_v<const T&, const charT*> is false.

33

#

Effects: Equivalent to:basic_string_view<charT, traits> sv = t;return assign(sv);

🔗

constexpr basic_string& operator=(const charT* s);

34

#

Effects: Equivalent to:return *this = basic_string_view<charT, traits>(s);

🔗

constexpr basic_string& operator=(charT c);

35

#

Effects: Equivalent to:return *this = basic_string_view<charT, traits>(addressof(c), 1);

🔗

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

36

#

Effects: Equivalent to:return *this = basic_string_view<charT, traits>(il.begin(), il.size());

27.4.3.4 Iterator support [string.iterators]

🔗

constexpr iterator begin() noexcept; constexpr const_iterator begin() const noexcept; constexpr const_iterator cbegin() const noexcept;

1

#

Returns: An iterator referring to the first character in the string.

🔗

constexpr iterator end() noexcept; constexpr const_iterator end() const noexcept; constexpr const_iterator cend() const noexcept;

2

#

Returns: An iterator which is the past-the-end value.

🔗

constexpr reverse_iterator rbegin() noexcept; constexpr const_reverse_iterator rbegin() const noexcept; constexpr const_reverse_iterator crbegin() const noexcept;

3

#

Returns: An iterator which is semantically equivalent toreverse_iterator(end()).

🔗

constexpr reverse_iterator rend() noexcept; constexpr const_reverse_iterator rend() const noexcept; constexpr const_reverse_iterator crend() const noexcept;

4

#

Returns: An iterator which is semantically equivalent toreverse_iterator(begin()).

27.4.3.5 Capacity [string.capacity]

🔗

constexpr size_type size() const noexcept; constexpr size_type length() const noexcept;

1

#

Returns: A count of the number of char-like objects currently in the string.

2

#

Complexity: Constant time.

🔗

constexpr size_type max_size() const noexcept;

3

#

Returns: The largest possible number of char-like objects that can be stored in abasic_string.

4

#

Complexity: Constant time.

🔗

constexpr void resize(size_type n, charT c);

5

#

Effects: Alters the value of*this as follows:

  • (5.1)

    Ifn <= size(), erases the last size() - n elements.

  • (5.2)

    Ifn > size(), appends n - size() copies of c.

🔗

constexpr void resize(size_type n);

6

#

Effects: Equivalent to resize(n, charT()).

🔗

template<class Operation> constexpr void resize_and_overwrite(size_type n, Operation op);

7

#

Let

  • (7.1)

    o = size() before the call to resize_and_overwrite.

  • (7.2)

    k be min(o, n).

  • (7.3)

    p be a value of type charT* or charT* const, such that the range [p, p + n] is valid andthis->compare(0, k, p, k) == 0 is true before the call. The values in the range [p + k, p + n] may be indeterminate ([basic.indet]).

  • (7.4)

    m be a value of type size_type or const size_type equal to n.

  • (7.5)

    OP be the expression std::move(op)(p, m).

  • (7.6)

    r = OP.

8

#

Mandates: OP has an integer-like type ([iterator.concept.winc]).

9

#

Preconditions:

  • (9.1)

    OP does not throw an exception or modify p or m.

  • (9.2)

    r ≥ 0.

  • (9.3)

    r ≤ m.

  • (9.4)

    After evaluating OP there are no indeterminate values in the range [p, p + r).

10

#

Effects: Evaluates OP, replaces the contents of *this with [p, p + r), and invalidates all pointers and references to the range [p, p + n].

11

#

Recommended practice: Implementations should avoid unnecessary copies and allocations by, for example, making p a pointer into internal storage and by restoring *(p + r) to charT() after evaluating OP.

🔗

constexpr size_type capacity() const noexcept;

12

#

Returns: The size of the allocated storage in the string.

13

#

Complexity: Constant time.

🔗

constexpr void reserve(size_type res_arg);

14

#

Effects: A directive that informs a basic_string of a planned change in size, so that the storage allocation can be managed accordingly.

Following a call toreserve,capacity() is greater or equal to the argument ofreserve if reallocation happens; and equal to the previous value ofcapacity() otherwise.

Reallocation happens at this point if and only if the current capacity is less than the argument of reserve.

15

#

Throws: length_error ifres_arg > max_size() or any exceptions thrown byallocator_traits ::allocate.

🔗

constexpr void shrink_to_fit();

16

#

Effects: shrink_to_fit is a non-binding request to reducecapacity() to size().

[Note 1:

The request is non-binding to allow latitude for implementation-specific optimizations.

— end note]

It does not increase capacity(), but may reduce capacity() by causing reallocation.

17

#

Complexity: If the size is not equal to the old capacity, linear in the size of the sequence; otherwise constant.

18

#

Remarks: Reallocation invalidates all the references, pointers, and iterators referring to the elements in the sequence, as well as the past-the-end iterator.

[Note 2:

If no reallocation happens, they remain valid.

— end note]

🔗

constexpr void clear() noexcept;

19

#

Effects: Equivalent to: erase(begin(), end());

🔗

constexpr bool empty() const noexcept;

20

#

Effects: Equivalent to:return size() == 0;

27.4.3.6 Element access [string.access]

🔗

constexpr const_reference operator[](size_type pos) const; constexpr reference operator[](size_type pos);

1

#

Hardened preconditions: pos <= size() is true.

2

#

Returns: *(begin() + pos) if pos < size().

Otherwise, returns a reference to an object of type charT with valuecharT(), where modifying the object to any value other thancharT() leads to undefined behavior.

3

#

Throws: Nothing.

4

#

Complexity: Constant time.

🔗

constexpr const_reference at(size_type pos) const; constexpr reference at(size_type pos);

5

#

Returns: operator.

6

#

Throws: out_of_range ifpos >= size().

🔗

constexpr const charT& front() const; constexpr charT& front();

7

#

Hardened preconditions: empty() is false.

8

#

Effects: Equivalent to: return operator;

🔗

constexpr const charT& back() const; constexpr charT& back();

9

#

Hardened preconditions: empty() is false.

10

#

Effects: Equivalent to: return operator[](size() - 1);

27.4.3.7 Modifiers [string.modifiers]

27.4.3.7.1 basic_string::operator+= [string.op.append]

🔗

constexpr basic_string& operator+=(const basic_string& str);

1

#

Effects: Equivalent to: return append(str);

🔗

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

2

#

Constraints:

is_convertible_v<const T&, basic_string_view<charT, traits>> istrue and

is_convertible_v<const T&, const charT*> isfalse.

3

#

Effects: Equivalent to:basic_string_view<charT, traits> sv = t;return append(sv);

🔗

constexpr basic_string& operator+=(const charT* s);

4

#

Effects: Equivalent to: return append(s);

🔗

constexpr basic_string& operator+=(charT c);

5

#

Effects: Equivalent to: return append(size_type{1}, c);

🔗

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

6

#

Effects: Equivalent to: return append(il);

27.4.3.7.2 basic_string::append [string.append]

🔗

constexpr basic_string& append(const basic_string& str);

1

#

Effects: Equivalent to: return append(str.data(), str.size());

🔗

constexpr basic_string& append(const basic_string& str, size_type pos, size_type n = npos);

2

#

Effects: Equivalent to:return append(basic_string_view<charT, traits>(str).substr(pos, n));

🔗

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

3

#

Constraints:

is_convertible_v<const T&, basic_string_view<charT, traits>> istrue and

is_convertible_v<const T&, const charT*> isfalse.

4

#

Effects: Equivalent to:basic_string_view<charT, traits> sv = t;return append(sv.data(), sv.size());

🔗

template<class T> constexpr basic_string& append(const T& t, size_type pos, size_type n = npos);

5

#

Constraints:

is_convertible_v<const T&, basic_string_view<charT, traits>> istrue and

is_convertible_v<const T&, const charT*> isfalse.

6

#

Effects: Equivalent to:basic_string_view<charT, traits> sv = t;return append(sv.substr(pos, n));

🔗

constexpr basic_string& append(const charT* s, size_type n);

7

#

Preconditions: [s, s + n) is a valid range.

8

#

Effects: Appends a copy of the range [s, s + n) to the string.

9

#

Returns: *this.

🔗

constexpr basic_string& append(const charT* s);

10

#

Effects: Equivalent to: return append(s, traits::length(s));

🔗

constexpr basic_string& append(size_type n, charT c);

11

#

Effects: Appends n copies of c to the string.

12

#

Returns: *this.

🔗

template<class InputIterator> constexpr basic_string& append(InputIterator first, InputIterator last);

13

#

Constraints: InputIterator is a type that qualifies as an input iterator ([container.reqmts]).

14

#

Effects: Equivalent to: return append(basic_string(first, last, get_allocator()));

🔗

template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<charT> R> constexpr basic_string& append_range(R&& rg);

15

#

Effects: Equivalent to: return append(basic_string(from_range, std::forward(rg), get_allocator()));

🔗

constexpr basic_string& append(initializer_list<charT> il);

16

#

Effects: Equivalent to: return append(il.begin(), il.size());

🔗

constexpr void push_back(charT c);

17

#

Effects: Equivalent toappend(size_type{1}, c).

27.4.3.7.3 basic_string::assign [string.assign]

🔗

constexpr basic_string& assign(const basic_string& str);

1

#

Effects: Equivalent to: return *this = str;

🔗

constexpr basic_string& assign(basic_string&& str) noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value || allocator_traits<Allocator>::is_always_equal::value);

2

#

Effects: Equivalent to: return *this = std::move(str);

🔗

constexpr basic_string& assign(const basic_string& str, size_type pos, size_type n = npos);

3

#

Effects: Equivalent to:return assign(basic_string_view<charT, traits>(str).substr(pos, n));

🔗

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

4

#

Constraints:

is_convertible_v<const T&, basic_string_view<charT, traits>> istrue and

is_convertible_v<const T&, const charT*> isfalse.

5

#

Effects: Equivalent to:basic_string_view<charT, traits> sv = t;return assign(sv.data(), sv.size());

🔗

template<class T> constexpr basic_string& assign(const T& t, size_type pos, size_type n = npos);

6

#

Constraints:

is_convertible_v<const T&, basic_string_view<charT, traits>> istrue and

is_convertible_v<const T&, const charT*> isfalse.

7

#

Effects: Equivalent to:basic_string_view<charT, traits> sv = t;return assign(sv.substr(pos, n));

🔗

constexpr basic_string& assign(const charT* s, size_type n);

8

#

Preconditions: [s, s + n) is a valid range.

9

#

Effects: Replaces the string controlled by *this with a copy of the range [s, s + n).

10

#

Returns: *this.

🔗

constexpr basic_string& assign(const charT* s);

11

#

Effects: Equivalent to: return assign(s, traits::length(s));

🔗

constexpr basic_string& assign(initializer_list<charT> il);

12

#

Effects: Equivalent to: return assign(il.begin(), il.size());

🔗

constexpr basic_string& assign(size_type n, charT c);

13

#

Effects: Equivalent to:clear(); resize(n, c);return *this;

🔗

template<class InputIterator> constexpr basic_string& assign(InputIterator first, InputIterator last);

14

#

Constraints: InputIterator is a type that qualifies as an input iterator ([container.reqmts]).

15

#

Effects: Equivalent to: return assign(basic_string(first, last, get_allocator()));

🔗

template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<charT> R> constexpr basic_string& assign_range(R&& rg);

16

#

Effects: Equivalent to: return assign(basic_string(from_range, std::forward(rg), get_allocator()));

27.4.3.7.4 basic_string::insert [string.insert]

🔗

constexpr basic_string& insert(size_type pos, const basic_string& str);

1

#

Effects: Equivalent to: return insert(pos, str.data(), str.size());

🔗

constexpr basic_string& insert(size_type pos1, const basic_string& str, size_type pos2, size_type n = npos);

2

#

Effects: Equivalent to:return insert(pos1, basic_string_view<charT, traits>(str), pos2, n);

🔗

template<class T> constexpr basic_string& insert(size_type pos, const T& t);

3

#

Constraints:

is_convertible_v<const T&, basic_string_view<charT, traits>> istrue and

is_convertible_v<const T&, const charT*> isfalse.

4

#

Effects: Equivalent to:basic_string_view<charT, traits> sv = t;return insert(pos, sv.data(), sv.size());

🔗

template<class T> constexpr basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n = npos);

5

#

Constraints:

is_convertible_v<const T&, basic_string_view<charT, traits>> istrue and

is_convertible_v<const T&, const charT*> isfalse.

6

#

Effects: Equivalent to:basic_string_view<charT, traits> sv = t;return insert(pos1, sv.substr(pos2, n));

🔗

constexpr basic_string& insert(size_type pos, const charT* s, size_type n);

7

#

Preconditions: [s, s + n) is a valid range.

8

#

Effects: Inserts a copy of the range [s, s + n) immediately before the character at position pos if pos < size(), or otherwise at the end of the string.

9

#

Returns: *this.

10

#

Throws:

out_of_range if pos > size(),

length_error if n > max_size() - size(), or

any exceptions thrown by allocator_traits::allocate.

🔗

constexpr basic_string& insert(size_type pos, const charT* s);

11

#

Effects: Equivalent to: return insert(pos, s, traits::length(s));

🔗

constexpr basic_string& insert(size_type pos, size_type n, charT c);

12

#

Effects: Inserts n copies of c before the character at position pos if pos < size(), or otherwise at the end of the string.

13

#

Returns: *this.

14

#

Throws:

out_of_range if pos > size(),

length_error if n > max_size() - size(), or

any exceptions thrown by allocator_traits::allocate.

🔗

constexpr iterator insert(const_iterator p, charT c);

15

#

Preconditions: p is a valid iterator on*this.

16

#

Effects: Inserts a copy of c at the position p.

17

#

Returns: An iterator which refers to the inserted character.

🔗

constexpr iterator insert(const_iterator p, size_type n, charT c);

18

#

Preconditions: p is a valid iterator on*this.

19

#

Effects: Inserts n copies of c at the position p.

20

#

Returns: An iterator which refers to the first inserted character, orp if n == 0.

🔗

template<class InputIterator> constexpr iterator insert(const_iterator p, InputIterator first, InputIterator last);

21

#

Constraints: InputIterator is a type that qualifies as an input iterator ([container.reqmts]).

22

#

Preconditions: p is a valid iterator on*this.

23

#

Effects: Equivalent toinsert(p - begin(), basic_string(first, last, get_allocator())).

24

#

Returns: An iterator which refers to the first inserted character, orp if first == last.

🔗

template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<charT> R> constexpr iterator insert_range(const_iterator p, R&& rg);

25

#

Preconditions: p is a valid iterator on *this.

26

#

Effects: Equivalent toinsert(p - begin(), basic_string(from_range, std::forward(rg), get_allocator())).

27

#

Returns: An iterator which refers to the first inserted character, orp if rg is empty.

🔗

constexpr iterator insert(const_iterator p, initializer_list<charT> il);

28

#

Effects: Equivalent to: return insert(p, il.begin(), il.end());

27.4.3.7.5 basic_string::erase [string.erase]

🔗

constexpr basic_string& erase(size_type pos = 0, size_type n = npos);

1

#

Effects: Determines the effective length xlen of the string to be removed as the smaller of n andsize() - pos.

Removes the characters in the range [begin() + pos, begin() + pos + xlen).

2

#

Returns: *this.

3

#

Throws: out_of_range if pos> size().

🔗

constexpr iterator erase(const_iterator p);

4

#

Preconditions: p is a valid dereferenceable iterator on *this.

5

#

Effects: Removes the character referred to by p.

6

#

Returns: An iterator which points to the element immediately following p prior to the element being erased.

If no such element exists,end() is returned.

7

#

Throws: Nothing.

🔗

constexpr iterator erase(const_iterator first, const_iterator last);

8

#

Preconditions: first and last are valid iterators on*this.

[first, last) is a valid range.

9

#

Effects: Removes the characters in the range [first, last).

10

#

Returns: An iterator which points to the element pointed to by last prior to the other elements being erased.

If no such element exists,end() is returned.

11

#

Throws: Nothing.

🔗

constexpr void pop_back();

12

#

Hardened preconditions: empty() is false.

13

#

Effects: Equivalent to erase(end() - 1).

14

#

Throws: Nothing.

27.4.3.7.6 basic_string::replace [string.replace]

🔗

constexpr basic_string& replace(size_type pos1, size_type n1, const basic_string& str);

1

#

Effects: Equivalent to: return replace(pos1, n1, str.data(), str.size());

🔗

constexpr basic_string& replace(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2 = npos);

2

#

Effects: Equivalent to:return replace(pos1, n1, basic_string_view<charT, traits>(str).substr(pos2, n2));

🔗

template<class T> constexpr basic_string& replace(size_type pos1, size_type n1, const T& t);

3

#

Constraints:

is_convertible_v<const T&, basic_string_view<charT, traits>> istrue and

is_convertible_v<const T&, const charT*> isfalse.

4

#

Effects: Equivalent to:basic_string_view<charT, traits> sv = t;return replace(pos1, n1, sv.data(), sv.size());

🔗

template<class T> constexpr basic_string& replace(size_type pos1, size_type n1, const T& t, size_type pos2, size_type n2 = npos);

5

#

Constraints:

is_convertible_v<const T&, basic_string_view<charT, traits>> istrue and

is_convertible_v<const T&, const charT*> isfalse.

6

#

Effects: Equivalent to:basic_string_view<charT, traits> sv = t;return replace(pos1, n1, sv.substr(pos2, n2));

🔗

constexpr basic_string& replace(size_type pos1, size_type n1, const charT* s, size_type n2);

7

#

Preconditions: [s, s + n2) is a valid range.

8

#

Effects: Determines the effective length xlen of the string to be removed as the smaller of n1 and size() - pos1.

Ifsize() - xlen >= max_size() - n2 throws length_error.

Otherwise, the function replaces the characters in the range [begin() + pos1, begin() + pos1 + xlen) with a copy of the range [s, s + n2).

9

#

Returns: *this.

10

#

Throws:

out_of_range if pos1 > size(),

length_error if the length of the resulting string would exceed max_size(), or

any exceptions thrown by allocator_traits::allocate.

🔗

constexpr basic_string& replace(size_type pos, size_type n, const charT* s);

11

#

Effects: Equivalent to: return replace(pos, n, s, traits::length(s));

🔗

constexpr basic_string& replace(size_type pos1, size_type n1, size_type n2, charT c);

12

#

Effects: Determines the effective length xlen of the string to be removed as the smaller of n1 and size() - pos1.

Ifsize() - xlen >= max_size() - n2 throws length_error.

Otherwise, the function replaces the characters in the range [begin() + pos1, begin() + pos1 + xlen) with n2 copies of c.

13

#

Returns: *this.

14

#

Throws:

out_of_range if pos1 > size(),

length_error if the length of the resulting string would exceed max_size(), or

any exceptions thrown by allocator_traits::allocate.

🔗

constexpr basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);

15

#

Effects: Equivalent to: return replace(i1, i2, basic_string_view<charT, traits>(str));

🔗

template<class T> constexpr basic_string& replace(const_iterator i1, const_iterator i2, const T& t);

16

#

Constraints:

is_convertible_v<const T&, basic_string_view<charT, traits>> istrue and

is_convertible_v<const T&, const charT*> isfalse.

17

#

Preconditions: [begin(), i1) and [i1, i2) are valid ranges.

18

#

Effects: Equivalent to:basic_string_view<charT, traits> sv = t;return replace(i1 - begin(), i2 - i1, sv.data(), sv.size());

🔗

constexpr basic_string& replace(const_iterator i1, const_iterator i2, const charT* s, size_type n);

19

#

Effects: Equivalent to: return replace(i1, i2, basic_string_view<charT, traits>(s, n));

🔗

constexpr basic_string& replace(const_iterator i1, const_iterator i2, const charT* s);

20

#

Effects: Equivalent to: return replace(i1, i2, basic_string_view<charT, traits>(s));

🔗

constexpr basic_string& replace(const_iterator i1, const_iterator i2, size_type n, charT c);

21

#

Preconditions: [begin(), i1) and [i1, i2) are valid ranges.

22

#

Effects: Equivalent to: return replace(i1 - begin(), i2 - i1, n, c);

🔗

template<class InputIterator> constexpr basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);

23

#

Constraints: InputIterator is a type that qualifies as an input iterator ([container.reqmts]).

24

#

Effects: Equivalent to: return replace(i1, i2, basic_string(j1, j2, get_allocator()));

🔗

template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<charT> R> constexpr basic_string& replace_with_range(const_iterator i1, const_iterator i2, R&& rg);

25

#

Effects: Equivalent to:return replace(i1, i2, basic_string(from_range, std::forward(rg), get_allocator()));

🔗

constexpr basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<charT> il);

26

#

Effects: Equivalent to: return replace(i1, i2, il.begin(), il.size());

27.4.3.7.7 basic_string::copy [string.copy]

🔗

constexpr size_type copy(charT* s, size_type n, size_type pos = 0) const;

1

#

Effects: Equivalent to:return basic_string_view<charT, traits>(*this).copy(s, n, pos);

[Note 1:

This does not terminate s with a null object.

— end note]

27.4.3.7.8 basic_string::swap [string.swap]

🔗

constexpr void swap(basic_string& s) noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value || allocator_traits<Allocator>::is_always_equal::value);

1

#

Preconditions: allocator_traits::propagate_on_container_swap::value is true orget_allocator() == s.get_allocator().

2

#

Postconditions: this contains the same sequence of characters that was in s,s contains the same sequence of characters that was inthis.

3

#

Throws: Nothing.

4

#

Complexity: Constant time.

27.4.3.8 String operations [string.ops]

27.4.3.8.1 Accessors [string.accessors]

🔗

constexpr const charT* c_str() const noexcept; constexpr const charT* data() const noexcept;

1

#

Returns: A pointer p such that p + i == addressof(operator) for eachi in [0, size()].

2

#

Complexity: Constant time.

3

#

Remarks: The program shall not modify any of the values stored in the character array; otherwise, the behavior is undefined.

🔗

constexpr charT* data() noexcept;

4

#

Returns: A pointer p such that p + i == addressof(operator) for eachi in [0, size()].

5

#

Complexity: Constant time.

6

#

Remarks: The program shall not modify the value stored at p + size() to any value other than charT(); otherwise, the behavior is undefined.

🔗

constexpr operator basic_string_view<charT, traits>() const noexcept;

7

#

Effects: Equivalent to:return basic_string_view<charT, traits>(data(), size());

🔗

constexpr allocator_type get_allocator() const noexcept;

8

#

Returns: A copy of theAllocator object used to construct the string or, if that allocator has been replaced, a copy of the most recent replacement.

27.4.3.8.2 Searching [string.find]

1

#

Let F be one offind, rfind, find_first_of, find_last_of,find_first_not_of, and find_last_not_of.

Each member function of the formconstexpr size_type F(const basic_string& str, size_type pos) const noexcept; has effects equivalent to:return F(basic_string_view<charT, traits>(str), pos);

Each member function of the formconstexpr size_type F(const charT* s, size_type pos) const; has effects equivalent to:return F(basic_string_view<charT, traits>(s), pos);

Each member function of the formconstexpr size_type F(const charT* s, size_type pos, size_type n) const; has effects equivalent to:return F(basic_string_view<charT, traits>(s, n), pos);

Each member function of the formconstexpr size_type F(charT c, size_type pos) const noexcept; has effects equivalent to:return F(basic_string_view<charT, traits>(addressof(c), 1), pos);

🔗

template<class T> constexpr size_type find(const T& t, size_type pos = 0) const noexcept(see below); template<class T> constexpr size_type rfind(const T& t, size_type pos = npos) const noexcept(see below); template<class T> constexpr size_type find_first_of(const T& t, size_type pos = 0) const noexcept(see below); template<class T> constexpr size_type find_last_of(const T& t, size_type pos = npos) const noexcept(see below); template<class T> constexpr size_type find_first_not_of(const T& t, size_type pos = 0) const noexcept(see below); template<class T> constexpr size_type find_last_not_of(const T& t, size_type pos = npos) const noexcept(see below);

2

#

Constraints:

is_convertible_v<const T&, basic_string_view<charT, traits>> istrue and

is_convertible_v<const T&, const charT*> isfalse.

3

#

Effects: Let G be the name of the function.

Equivalent to:basic_string_view<charT, traits> s = *this, sv = t;return s.G(sv, pos);

4

#

Remarks: The exception specification is equivalent tois_nothrow_convertible_v<const T&, basic_string_view<charT, traits>>.

27.4.3.8.3 basic_string::substr [string.substr]

🔗

constexpr basic_string substr(size_type pos = 0, size_type n = npos) const &;

1

#

Effects: Equivalent to: return basic_string(*this, pos, n);

🔗

constexpr basic_string substr(size_type pos = 0, size_type n = npos) &&;

2

#

Effects: Equivalent to: return basic_string(std::move(*this), pos, n);

🔗

constexpr basic_string_view<charT, traits> subview(size_type pos = 0, size_type n = npos) const;

3

#

Effects: Equivalent to: return basic_string_view<charT, traits>(*this).subview(pos, n);

27.4.3.8.4 basic_string::compare [string.compare]

🔗

template<class T> constexpr int compare(const T& t) const noexcept(see below);

1

#

Constraints:

is_convertible_v<const T&, basic_string_view<charT, traits>> istrue and

is_convertible_v<const T&, const charT*> isfalse.

2

#

Effects: Equivalent to: return basic_string_view<charT, traits>(*this).compare(t);

3

#

Remarks: The exception specification is equivalent tois_nothrow_convertible_v<const T&, basic_string_view<charT, traits>>.

🔗

template<class T> constexpr int compare(size_type pos1, size_type n1, const T& t) const;

4

#

Constraints:

is_convertible_v<const T&, basic_string_view<charT, traits>> istrue and

is_convertible_v<const T&, const charT*> isfalse.

5

#

Effects: Equivalent to:return basic_string_view<charT, traits>(*this).substr(pos1, n1).compare(t);

🔗

template<class T> constexpr int compare(size_type pos1, size_type n1, const T& t, size_type pos2, size_type n2 = npos) const;

6

#

Constraints:

is_convertible_v<const T&, basic_string_view<charT, traits>> istrue and

is_convertible_v<const T&, const charT*> isfalse.

7

#

Effects: Equivalent to:basic_string_view<charT, traits> s = *this, sv = t;return s.substr(pos1, n1).compare(sv.substr(pos2, n2));

🔗

constexpr int compare(const basic_string& str) const noexcept;

8

#

Effects: Equivalent to:return compare(basic_string_view<charT, traits>(str));

🔗

constexpr int compare(size_type pos1, size_type n1, const basic_string& str) const;

9

#

Effects: Equivalent to:return compare(pos1, n1, basic_string_view<charT, traits>(str));

🔗

constexpr int compare(size_type pos1, size_type n1, const basic_string& str, size_type pos2, size_type n2 = npos) const;

10

#

Effects: Equivalent to:return compare(pos1, n1, basic_string_view<charT, traits>(str), pos2, n2);

🔗

constexpr int compare(const charT* s) const;

11

#

Effects: Equivalent to:return compare(basic_string_view<charT, traits>(s));

🔗

constexpr int compare(size_type pos, size_type n1, const charT* s) const;

12

#

Effects: Equivalent to: return compare(pos, n1, basic_string_view<charT, traits>(s));

🔗

constexpr int compare(size_type pos, size_type n1, const charT* s, size_type n2) const;

13

#

Effects: Equivalent to: return compare(pos, n1, basic_string_view<charT, traits>(s, n2));

27.4.3.8.5 basic_string::starts_with [string.starts.with]

🔗

constexpr bool starts_with(basic_string_view<charT, traits> x) const noexcept; constexpr bool starts_with(charT x) const noexcept; constexpr bool starts_with(const charT* x) const;

1

#

Effects: Equivalent to:return basic_string_view<charT, traits>(data(), size()).starts_with(x);

27.4.3.8.6 basic_string::ends_with [string.ends.with]

🔗

constexpr bool ends_with(basic_string_view<charT, traits> x) const noexcept; constexpr bool ends_with(charT x) const noexcept; constexpr bool ends_with(const charT* x) const;

1

#

Effects: Equivalent to:return basic_string_view<charT, traits>(data(), size()).ends_with(x);

27.4.3.8.7 basic_string::contains [string.contains]

🔗

constexpr bool contains(basic_string_view<charT, traits> x) const noexcept; constexpr bool contains(charT x) const noexcept; constexpr bool contains(const charT* x) const;

1

#

Effects: Equivalent to:return basic_string_view<charT, traits>(data(), size()).contains(x);