[string.ops] (original) (raw)

21 Strings library [strings]

21.3 String classes [string.classes]

21.3.2 Class template basic_­string [basic.string]

21.3.2.7 String operations [string.ops]

21.3.2.7.1 Accessors [string.accessors]

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

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

Complexity:Constant time.

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

constexpr charT* data() noexcept;

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

Complexity:Constant time.

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;

Effects:Equivalent to:return basic_­string_­view<charT, traits>(data(), size());

constexpr allocator_type get_allocator() const noexcept;

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

21.3.2.7.2 Searching [string.find]

Let F be one offind, rfind, find_­first_­of, find_­last_­of,find_­first_­not_­of, and find_­last_­not_­of.

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

Constraints:

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

Remarks:The expression inside noexcept is equivalent tois_­nothrow_­convertible_­v<const T&, basic_­string_­view<charT, traits>>.

21.3.2.7.3 basic_­string​::​substr [string.substr]

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

Throws: out_­of_­rangeifpos > size().

Effects:Determines the effective length rlen of the string to copy as the smaller of n andsize() - pos.

Returns: basic_­string(data()+pos, rlen).

21.3.2.7.4 basic_­string​::​compare [string.compare]

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

Constraints:

Effects:Equivalent to: return basic_­string_­view<charT, traits>(*this).compare(t);

Remarks:The expression inside noexcept 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;

Constraints:

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;

Constraints:

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;

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;

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;

Effects:Equivalent to:

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

constexpr int compare(const charT* s) const;

Effects:Equivalent to:return compare(basic_­string_­view<charT, traits>(s));

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

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;

Effects:Equivalent to: return compare(pos, n1, basic_­string_­view<charT, traits>(s, n2));

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

Effects:Equivalent to:

return basic_string_view<charT, traits>(data(), size()).starts_with(x);

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

Effects:Equivalent to:

return basic_string_view<charT, traits>(data(), size()).ends_with(x);