#include <initializer_list>
namespace std {
template<class charT> struct char_traits;
template<> struct char_traits<char>;
template<> struct char_traits<char16_t>;
template<> struct char_traits<char32_t>;
template<> struct char_traits<wchar_t>;
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
class basic_string;
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(const basic_string<charT, traits, Allocator>& lhs,
const basic_string<charT, traits, Allocator>& rhs);
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(basic_string<charT, traits, Allocator>&& lhs,
const basic_string<charT, traits, Allocator>& rhs);
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(const basic_string<charT, traits, Allocator>& lhs,
basic_string<charT, traits, Allocator>&& rhs);
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(basic_string<charT, traits, Allocator>&& lhs,
basic_string<charT, traits, Allocator>&& rhs);
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(const charT* lhs,
const basic_string<charT, traits, Allocator>& rhs);
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(const charT* lhs,
basic_string<charT, traits, Allocator>&& rhs);
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(charT lhs,
const basic_string<charT, traits, Allocator>& rhs);
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(charT lhs,
basic_string<charT, traits, Allocator>&& rhs);
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(const basic_string<charT, traits, Allocator>& lhs,
const charT* rhs);
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(basic_string<charT, traits, Allocator>&& lhs,
const charT* rhs);
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(const basic_string<charT, traits, Allocator>& lhs,
charT rhs);
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(basic_string<charT, traits, Allocator>&& lhs,
charT rhs);
template<class charT, class traits, class Allocator>
bool operator==(const basic_string<charT, traits, Allocator>& lhs,
const basic_string<charT, traits, Allocator>& rhs) noexcept;
template<class charT, class traits, class Allocator>
bool operator==(const charT* lhs,
const basic_string<charT, traits, Allocator>& rhs);
template<class charT, class traits, class Allocator>
bool operator==(const basic_string<charT, traits, Allocator>& lhs,
const charT* rhs);
template<class charT, class traits, class Allocator>
bool operator!=(const basic_string<charT, traits, Allocator>& lhs,
const basic_string<charT, traits, Allocator>& rhs) noexcept;
template<class charT, class traits, class Allocator>
bool operator!=(const charT* lhs,
const basic_string<charT, traits, Allocator>& rhs);
template<class charT, class traits, class Allocator>
bool operator!=(const basic_string<charT, traits, Allocator>& lhs,
const charT* rhs);
template<class charT, class traits, class Allocator>
bool operator< (const basic_string<charT, traits, Allocator>& lhs,
const basic_string<charT, traits, Allocator>& rhs) noexcept;
template<class charT, class traits, class Allocator>
bool operator< (const basic_string<charT, traits, Allocator>& lhs,
const charT* rhs);
template<class charT, class traits, class Allocator>
bool operator< (const charT* lhs,
const basic_string<charT, traits, Allocator>& rhs);
template<class charT, class traits, class Allocator>
bool operator> (const basic_string<charT, traits, Allocator>& lhs,
const basic_string<charT, traits, Allocator>& rhs) noexcept;
template<class charT, class traits, class Allocator>
bool operator> (const basic_string<charT, traits, Allocator>& lhs,
const charT* rhs);
template<class charT, class traits, class Allocator>
bool operator> (const charT* lhs,
const basic_string<charT, traits, Allocator>& rhs);
template<class charT, class traits, class Allocator>
bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
const basic_string<charT, traits, Allocator>& rhs) noexcept;
template<class charT, class traits, class Allocator>
bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
const charT* rhs);
template<class charT, class traits, class Allocator>
bool operator<=(const charT* lhs,
const basic_string<charT, traits, Allocator>& rhs);
template<class charT, class traits, class Allocator>
bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
const basic_string<charT, traits, Allocator>& rhs) noexcept;
template<class charT, class traits, class Allocator>
bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
const charT* rhs);
template<class charT, class traits, class Allocator>
bool operator>=(const charT* lhs,
const basic_string<charT, traits, Allocator>& rhs);
template<class charT, class traits, class Allocator>
void swap(basic_string<charT, traits, Allocator>& lhs,
basic_string<charT, traits, Allocator>& rhs)
noexcept(noexcept(lhs.swap(rhs)));
template<class charT, class traits, class Allocator>
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is,
basic_string<charT, traits, Allocator>& str);
template<class charT, class traits, class Allocator>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const basic_string<charT, traits, Allocator>& str);
template<class charT, class traits, class Allocator>
basic_istream<charT, traits>&
getline(basic_istream<charT, traits>& is,
basic_string<charT, traits, Allocator>& str,
charT delim);
template<class charT, class traits, class Allocator>
basic_istream<charT, traits>&
getline(basic_istream<charT, traits>&& is,
basic_string<charT, traits, Allocator>& str,
charT delim);
template<class charT, class traits, class Allocator>
basic_istream<charT, traits>&
getline(basic_istream<charT, traits>& is,
basic_string<charT, traits, Allocator>& str);
template<class charT, class traits, class Allocator>
basic_istream<charT, traits>&
getline(basic_istream<charT, traits>&& is,
basic_string<charT, traits, Allocator>& str);
using string = basic_string<char>;
using u16string = basic_string<char16_t>;
using u32string = basic_string<char32_t>;
using wstring = basic_string<wchar_t>;
int stoi(const string& str, size_t* idx = nullptr, int base = 10);
long stol(const string& str, size_t* idx = nullptr, int base = 10);
unsigned long stoul(const string& str, size_t* idx = nullptr, int base = 10);
long long stoll(const string& str, size_t* idx = nullptr, int base = 10);
unsigned long long stoull(const string& str, size_t* idx = nullptr, int base = 10);
float stof(const string& str, size_t* idx = nullptr);
double stod(const string& str, size_t* idx = nullptr);
long double stold(const string& str, size_t* idx = nullptr);
string to_string(int val);
string to_string(unsigned val);
string to_string(long val);
string to_string(unsigned long val);
string to_string(long long val);
string to_string(unsigned long long val);
string to_string(float val);
string to_string(double val);
string to_string(long double val);
int stoi(const wstring& str, size_t* idx = nullptr, int base = 10);
long stol(const wstring& str, size_t* idx = nullptr, int base = 10);
unsigned long stoul(const wstring& str, size_t* idx = nullptr, int base = 10);
long long stoll(const wstring& str, size_t* idx = nullptr, int base = 10);
unsigned long long stoull(const wstring& str, size_t* idx = nullptr, int base = 10);
float stof(const wstring& str, size_t* idx = nullptr);
double stod(const wstring& str, size_t* idx = nullptr);
long double stold(const wstring& str, size_t* idx = nullptr);
wstring to_wstring(int val);
wstring to_wstring(unsigned val);
wstring to_wstring(long val);
wstring to_wstring(unsigned long val);
wstring to_wstring(long long val);
wstring to_wstring(unsigned long long val);
wstring to_wstring(float val);
wstring to_wstring(double val);
wstring to_wstring(long double val);
namespace pmr {
template<class charT, class traits = char_traits<charT>>
using basic_string = std::basic_string<charT, traits, polymorphic_allocator<charT>>;
using string = basic_string<char>;
using u16string = basic_string<char16_t>;
using u32string = basic_string<char32_t>;
using wstring = basic_string<wchar_t>;
}
template<class T> struct hash;
template<> struct hash<string>;
template<> struct hash<u16string>;
template<> struct hash<u32string>;
template<> struct hash<wstring>;
template<> struct hash<pmr::string>;
template<> struct hash<pmr::u16string>;
template<> struct hash<pmr::u32string>;
template<> struct hash<pmr::wstring>;
inline namespace literals {
inline namespace string_literals {
string operator""s(const char* str, size_t len);
u16string operator""s(const char16_t* str, size_t len);
u32string operator""s(const char32_t* str, size_t len);
wstring operator""s(const wchar_t* str, size_t len);
}
}
}
The
class template
basic_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 this Clause,
the type of the char-like objects held in a
basic_string object
is designated by
charT.The
member functions of
basic_string use an object of the
Allocator
class passed as a template parameter to allocate and free storage for the
contained char-like objects
.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.The functions described in this Clause can report two
kinds of errors, each associated with an exception type:
namespace std {
template<class charT, class traits = char_traits<charT>,
class Allocator = allocator<charT>>
class basic_string {
public:
using traits_type = traits;
using value_type = charT;
using allocator_type = Allocator;
using size_type = typename allocator_traits<Allocator>::size_type;
using difference_type = typename allocator_traits<Allocator>::difference_type;
using pointer = typename allocator_traits<Allocator>::pointer;
using const_pointer = typename allocator_traits<Allocator>::const_pointer;
using reference = value_type&;
using const_reference = const value_type&;
using iterator = implementation-defined; using const_iterator = implementation-defined; using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
static const size_type npos = -1;
basic_string() noexcept(noexcept(Allocator())) : basic_string(Allocator()) { }
explicit basic_string(const Allocator& a) noexcept;
basic_string(const basic_string& str);
basic_string(basic_string&& str) noexcept;
basic_string(const basic_string& str, size_type pos, const Allocator& a = Allocator());
basic_string(const basic_string& str, size_type pos, size_type n,
const Allocator& a = Allocator());
template<class T>
basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator());
template<class T>
explicit basic_string(const T& t, const Allocator& a = Allocator());
basic_string(const charT* s, size_type n, const Allocator& a = Allocator());
basic_string(const charT* s, const Allocator& a = Allocator());
basic_string(size_type n, charT c, const Allocator& a = Allocator());
template<class InputIterator>
basic_string(InputIterator begin, InputIterator end, const Allocator& a = Allocator());
basic_string(initializer_list<charT>, const Allocator& = Allocator());
basic_string(const basic_string&, const Allocator&);
basic_string(basic_string&&, const Allocator&);
~basic_string();
basic_string& operator=(const basic_string& str);
basic_string& operator=(basic_string&& str)
noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
allocator_traits<Allocator>::is_always_equal::value);
template<class T>
basic_string& operator=(const T& t);
basic_string& operator=(const charT* s);
basic_string& operator=(charT c);
basic_string& operator=(initializer_list<charT>);
iterator begin() noexcept;
const_iterator begin() const noexcept;
iterator end() noexcept;
const_iterator end() const noexcept;
reverse_iterator rbegin() noexcept;
const_reverse_iterator rbegin() const noexcept;
reverse_iterator rend() noexcept;
const_reverse_iterator rend() const noexcept;
const_iterator cbegin() const noexcept;
const_iterator cend() const noexcept;
const_reverse_iterator crbegin() const noexcept;
const_reverse_iterator crend() const noexcept;
size_type size() const noexcept;
size_type length() const noexcept;
size_type max_size() const noexcept;
void resize(size_type n, charT c);
void resize(size_type n);
size_type capacity() const noexcept;
void reserve(size_type res_arg);
void shrink_to_fit();
void clear() noexcept;
[[nodiscard]] bool empty() const noexcept;
const_reference operator[](size_type pos) const;
reference operator[](size_type pos);
const_reference at(size_type n) const;
reference at(size_type n);
const charT& front() const;
charT& front();
const charT& back() const;
charT& back();
basic_string& operator+=(const basic_string& str);
template<class T>
basic_string& operator+=(const T& t);
basic_string& operator+=(const charT* s);
basic_string& operator+=(charT c);
basic_string& operator+=(initializer_list<charT>);
basic_string& append(const basic_string& str);
basic_string& append(const basic_string& str, size_type pos, size_type n = npos);
template<class T>
basic_string& append(const T& t);
template<class T>
basic_string& append(const T& t, size_type pos, size_type n = npos);
basic_string& append(const charT* s, size_type n);
basic_string& append(const charT* s);
basic_string& append(size_type n, charT c);
template<class InputIterator>
basic_string& append(InputIterator first, InputIterator last);
basic_string& append(initializer_list<charT>);
void push_back(charT c);
basic_string& assign(const basic_string& str);
basic_string& assign(basic_string&& str)
noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
allocator_traits<Allocator>::is_always_equal::value);
basic_string& assign(const basic_string& str, size_type pos, size_type n = npos);
template<class T>
basic_string& assign(const T& t);
template<class T>
basic_string& assign(const T& t, size_type pos, size_type n = npos);
basic_string& assign(const charT* s, size_type n);
basic_string& assign(const charT* s);
basic_string& assign(size_type n, charT c);
template<class InputIterator>
basic_string& assign(InputIterator first, InputIterator last);
basic_string& assign(initializer_list<charT>);
basic_string& insert(size_type pos, const basic_string& str);
basic_string& insert(size_type pos1, const basic_string& str,
size_type pos2, size_type n = npos);
template<class T>
basic_string& insert(size_type pos, const T& t);
template<class T>
basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n = npos);
basic_string& insert(size_type pos, const charT* s, size_type n);
basic_string& insert(size_type pos, const charT* s);
basic_string& insert(size_type pos, size_type n, charT c);
iterator insert(const_iterator p, charT c);
iterator insert(const_iterator p, size_type n, charT c);
template<class InputIterator>
iterator insert(const_iterator p, InputIterator first, InputIterator last);
iterator insert(const_iterator p, initializer_list<charT>);
basic_string& erase(size_type pos = 0, size_type n = npos);
iterator erase(const_iterator p);
iterator erase(const_iterator first, const_iterator last);
void pop_back();
basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
size_type pos2, size_type n2 = npos);
template<class T>
basic_string& replace(size_type pos1, size_type n1, const T& t);
template<class T>
basic_string& replace(size_type pos1, size_type n1, const T& t,
size_type pos2, size_type n2 = npos);
basic_string& replace(size_type pos, size_type n1, const charT* s, size_type n2);
basic_string& replace(size_type pos, size_type n1, const charT* s);
basic_string& replace(size_type pos, size_type n1, size_type n2, charT c);
basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
template<class T>
basic_string& replace(const_iterator i1, const_iterator i2, const T& t);
basic_string& replace(const_iterator i1, const_iterator i2, const charT* s, size_type n);
basic_string& replace(const_iterator i1, const_iterator i2, const charT* s);
basic_string& replace(const_iterator i1, const_iterator i2, size_type n, charT c);
template<class InputIterator>
basic_string& replace(const_iterator i1, const_iterator i2,
InputIterator j1, InputIterator j2);
basic_string& replace(const_iterator, const_iterator, initializer_list<charT>);
size_type copy(charT* s, size_type n, size_type pos = 0) const;
void swap(basic_string& str)
noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
allocator_traits<Allocator>::is_always_equal::value);
const charT* c_str() const noexcept;
const charT* data() const noexcept;
charT* data() noexcept;
operator basic_string_view<charT, traits>() const noexcept;
allocator_type get_allocator() const noexcept;
template<class T>
size_type find (const T& t, size_type pos = 0) const;
size_type find (const basic_string& str, size_type pos = 0) const noexcept;
size_type find (const charT* s, size_type pos, size_type n) const;
size_type find (const charT* s, size_type pos = 0) const;
size_type find (charT c, size_type pos = 0) const;
template<class T>
size_type rfind(const T& t, size_type pos = npos) const;
size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
size_type rfind(const charT* s, size_type pos, size_type n) const;
size_type rfind(const charT* s, size_type pos = npos) const;
size_type rfind(charT c, size_type pos = npos) const;
template<class T>
size_type find_first_of(const T& t, size_type pos = 0) const;
size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
size_type find_first_of(const charT* s, size_type pos, size_type n) const;
size_type find_first_of(const charT* s, size_type pos = 0) const;
size_type find_first_of(charT c, size_type pos = 0) const;
template<class T>
size_type find_last_of (const T& t, size_type pos = npos) const;
size_type find_last_of (const basic_string& str, size_type pos = npos) const noexcept;
size_type find_last_of (const charT* s, size_type pos, size_type n) const;
size_type find_last_of (const charT* s, size_type pos = npos) const;
size_type find_last_of (charT c, size_type pos = npos) const;
template<class T>
size_type find_first_not_of(const T& t, size_type pos = 0) const;
size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
size_type find_first_not_of(const charT* s, size_type pos, size_type n) const;
size_type find_first_not_of(const charT* s, size_type pos = 0) const;
size_type find_first_not_of(charT c, size_type pos = 0) const;
template<class T>
size_type find_last_not_of (const T& t, size_type pos = npos) const;
size_type find_last_not_of (const basic_string& str, size_type pos = npos) const noexcept;
size_type find_last_not_of (const charT* s, size_type pos, size_type n) const;
size_type find_last_not_of (const charT* s, size_type pos = npos) const;
size_type find_last_not_of (charT c, size_type pos = npos) const;
basic_string substr(size_type pos = 0, size_type n = npos) const;
template<class T>
int compare(const T& t) const;
template<class T>
int compare(size_type pos1, size_type n1, const T& t) const;
template<class T>
int compare(size_type pos1, size_type n1, const T& t,
size_type pos2, size_type n2 = npos) const;
int compare(const basic_string& str) const noexcept;
int compare(size_type pos1, size_type n1, const basic_string& str) const;
int compare(size_type pos1, size_type n1, const basic_string& str,
size_type pos2, size_type n2 = npos) const;
int compare(const charT* s) const;
int compare(size_type pos1, size_type n1, const charT* s) const;
int compare(size_type pos1, size_type n1, const charT* s, size_type n2) const;
bool starts_with(basic_string_view<charT, traits> x) const noexcept;
bool starts_with(charT x) const noexcept;
bool starts_with(const charT* x) const;
bool ends_with(basic_string_view<charT, traits> x) const noexcept;
bool ends_with(charT x) const noexcept;
bool ends_with(const charT* x) const;
};
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>;
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>;
}
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
.If any operation would cause
size() to
exceed
max_size(), that operation shall throw an
exception object of type
length_error.If any member function or operator of
basic_string throws an exception, that
function or operator shall have no other effect
.In every specialization
basic_string<charT, traits, Allocator>,
the type
allocator_traits<Allocator>::value_type shall name the same type
as
charT. Every object of type
basic_string<charT, traits, Allocator> shall use an object of type
Allocator to allocate and free storage for the contained
charT
objects as needed
. In every specialization
basic_string<charT, traits, Allocator>,
the type
traits shall satisfy
the character traits requirements (
[char.traits]), and
the type
traits::char_type shall name the same type as
charT.References, pointers, and iterators referring to the elements of a
basic_string sequence may be
invalidated by the following uses of that basic_string object:
as an argument to any standard library function taking a reference to non-const
basic_string as an argument
.Calling non-const member functions, except
operator[],
at,
data,
front,
back,
begin,
rbegin,
end,
and
rend.
explicit basic_string(const Allocator& a) noexcept;
Effects:
Constructs an object of class
basic_string. Ensures:
size() is
0 and
capacity() is an unspecified value
. basic_string(const basic_string& str);
basic_string(basic_string&& str) noexcept;
Effects:
Constructs an object of class
basic_string. Ensures:
data() points at the first element of an allocated copy
of the array whose first element is pointed at by the original
value
str.data(),
size() is equal to the
original value of
str.size(), and
capacity() is a value
at least as large as
size(). In the second form,
str is left in a valid state with an unspecified value
.basic_string(const basic_string& str, size_type pos,
const Allocator& a = Allocator());
basic_string(const basic_string& str, size_type pos, size_type n,
const Allocator& a = Allocator());
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
str.size() - pos in the first form and
as the smaller of
str.size() - pos and
n in the second form
. Ensures:
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() is equal to
rlen, and
capacity() is a
value at least as large as
size(). template<class T>
basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator());
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);
Remarks: This constructor shall not participate in overload resolution
unless
is_convertible_v<const T&, basic_string_view<charT, traits>>
is
true. template<class T>
explicit basic_string(const T& t, const Allocator& a = Allocator());
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). Remarks: This constructor shall not participate in overload resolution unless
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. Ensures:
data() points at the first element of an allocated copy
of the array whose first element is pointed at by
s,
size() is equal to
n, and
capacity() is
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. Ensures:
data() points at the first element of an allocated copy
of the array whose first element is pointed at by
s,
size() is equal to
traits::length(s), and
capacity() is a value at least as large as
size(). [
βNote: This affects class template argument deduction
. β
βend note β]
basic_string(size_type n, charT c, const Allocator& a = Allocator());
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
. Ensures:
data() points at the first element of an allocated array
of
n elements, each storing the initial value
c,
size() is equal to
n, and
capacity() is a value at least as large as
size(). [
βNote: This affects class template argument deduction
. β
βend note β]
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. The stored allocator is constructed from
alloc.Ensures:
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() is equal to the
original value of
str.size(),
capacity() is a value
at least as large as
size(), and
get_allocator() is
equal to
alloc. In the second form,
str is left in a valid state with an
unspecified value
.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>;
Remarks: Shall not participate in overload resolution if
InputIterator is a type that does not qualify as an input iterator,
or if
Allocator is a type that does not qualify 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>;
basic_string& operator=(const basic_string& str);
Ensures:
If
*this and
str are the same object, the member has no effect
. Otherwise,
data() points at the first element of an allocated copy
of the array whose first element is pointed at by
str.data(),
size() is equal to
str.size(), and
capacity() is a value at least as large as
size().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
. template<class T>
basic_string& operator=(const T& t);
Effects: Equivalent to:
{
basic_string_view<charT, traits> sv = t;
return assign(sv);
}
Remarks: This function shall not participate in overload resolution unless
is_convertible_v<const T&, basic_string_view<charT, traits>> is
true and
is_convertible_v<const T&, const charT*> is
false. 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: As if by: *this = basic_string(il);
iterator begin() noexcept;
const_iterator begin() const noexcept;
const_iterator cbegin() const noexcept;
Returns:
An iterator referring to the first character in the string
. iterator end() noexcept;
const_iterator end() const noexcept;
const_iterator cend() const noexcept;
Returns:
An iterator which is the past-the-end value
. reverse_iterator rbegin() noexcept;
const_reverse_iterator rbegin() const noexcept;
const_reverse_iterator crbegin() const noexcept;
Returns:
An iterator which is semantically equivalent to
reverse_iterator(end()). reverse_iterator rend() noexcept;
const_reverse_iterator rend() const noexcept;
const_reverse_iterator crend() const noexcept;
Returns:
An iterator which is semantically equivalent to
reverse_iterator(begin()). size_type size() const noexcept;
Returns:
A count of the number of char-like objects currently in the string
. Complexity: Constant time
. size_type length() const noexcept;
size_type max_size() const noexcept;
Returns:
The largest possible number of char-like objects that can be stored in a
basic_string. Complexity: Constant time
. void resize(size_type n, charT c);
Throws:
length_error
if
n > max_size(). Effects:
Alters the length of the string designated by
*this
as follows:
If
n <= size(),
the function replaces the string designated by
*this
with a string of length
n whose elements are a
copy of the initial elements of the original string designated by
*this.If
n > size(),
the function replaces the string designated by
*this
with a string of length
n whose first
size()
elements are a copy of the original string designated by
*this,
and whose remaining elements are all initialized to
c.
void resize(size_type n);
Effects:
As if by
resize(n, charT()). size_type capacity() const noexcept;
Returns:
The size of the allocated storage in the string
. Complexity: Constant time
. void reserve(size_type res_arg);
Effects:
A directive that informs a
basic_string of a planned change in size,
so that the storage allocation can be managed accordingly
. After
reserve(),
capacity()
is greater or equal to the argument of
reserve
if reallocation happens; and
equal to the previous value of
capacity()
otherwise
. Reallocation happens at this point if and only if
the current capacity is less than the argument of
reserve().Throws:
length_error
if
res_arg > max_size(). Effects: shrink_to_fit is a non-binding request to reduce
capacity() to
size(). [
βNote: 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
.Complexity: Linear in the size of the sequence
. Remarks: Reallocation invalidates all the references, pointers, and iterators
referring to the elements in the sequence as well as the past-the-end iterator
. If no reallocation happens, they remain valid
.Effects:
Behaves as if the function calls:
erase(begin(), end());
[[nodiscard]] bool empty() const noexcept;
const_reference operator[](size_type pos) const;
reference operator[](size_type pos);
Returns: *(begin() + pos) if
pos < size(). Otherwise,
returns a reference to an object of type
charT with value
charT(), where modifying the object to any value other than
charT() leads to undefined behavior
.Complexity: Constant time
.
const_reference at(size_type pos) const;
reference at(size_type pos);
Throws:
out_of_range
if
pos >= size(). Returns:
operator[](pos).
const charT& front() const;
charT& front();
Effects:
Equivalent to: return operator[](0);
const charT& back() const;
charT& back();
Effects:
Equivalent to: return operator[](size() - 1);
basic_string& operator+=(const basic_string& str);
Effects: Calls
append(str). template<class T>
basic_string& operator+=(const T& t);
Effects:
Creates a variable,
sv, as if by
basic_string_view<charT, traits> sv = t; and
then calls
append(sv). Remarks:
This function shall not participate in overload resolution unless
is_convertible_v<const T&, basic_string_view<charT, traits>> is
true and
is_convertible_v<const T&, const charT*> is
false. basic_string& operator+=(const charT* s);
Effects: Calls
append(s). basic_string& operator+=(charT c);
Effects: Calls push_back(c);
basic_string& operator+=(initializer_list<charT> il);
Effects: Calls
append(il). basic_string& append(const basic_string& str);
Effects: Calls
append(str.data(), str.size()). basic_string& append(const basic_string& str, size_type pos, size_type n = npos);
Throws:
out_of_range
if
pos > str.size(). Effects:
Determines the effective length
rlen
of the string to append as the smaller of
n and
str.size() - pos and calls
append(str.data() + pos, rlen). template<class T>
basic_string& append(const T& t);
Effects:
Equivalent to:
{
basic_string_view<charT, traits> sv = t;
return append(sv.data(), sv.size());
}
Remarks:
This function shall not participate in overload resolution unless
is_convertible_v<const T&, basic_string_view<charT, traits>> is
true and
is_convertible_v<const T&, const charT*> is
false. template<class T>
basic_string& append(const T& t, size_type pos, size_type n = npos);
Throws:
out_of_range
if
pos > sv.size(). Effects:
Creates a variable,
sv, as if by
basic_string_view<charT, traits> sv = t. Determines the effective length
rlen of the string to append
as the smaller of
n and
sv.size() - pos
and calls
append(sv.data() + pos, rlen).Remarks:
This function shall not participate in overload resolution
unless
is_convertible_v<const T&, basic_string_view<charT, traits>>
is
true and
is_convertible_v<const T&, const charT*> is
false. basic_string& append(const charT* s, size_type n);
Requires: s points to an array of at least
n elements
of
charT. Throws: length_error if
size() + n > max_size(). Effects: The function replaces the string controlled by
*this
with a string of length
size() + n whose first
size()
elements are a copy of the original string controlled by
*this
and whose remaining elements are a copy of the initial
n elements
of
s. basic_string& append(const charT* s);
Requires: s points to an array of at least
traits::length(s) + 1
elements of
charT. Effects: Calls
append(s, traits::length(s)). basic_string& append(size_type n, charT c);
Effects: Equivalent to: return append(basic_string(n, c));
template<class InputIterator>
basic_string& append(InputIterator first, InputIterator last);
Requires: [first, last) is a valid range
. Effects: Equivalent to: return append(basic_string(first, last, get_allocator()));
basic_string& append(initializer_list<charT> il);
Effects: Calls
append(il.begin(), il.size()). Effects:
Equivalent to
append(static_cast<size_type>(1), c). basic_string& assign(const basic_string& str);
Effects: Equivalent to: return *this = str;
basic_string& assign(basic_string&& str)
noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
allocator_traits<Allocator>::is_always_equal::value);
Effects: Equivalent to: return *this = std::move(str);
basic_string& assign(const basic_string& str, size_type pos, size_type n = npos);
Throws:
out_of_range
if
pos > str.size(). Effects:
Determines the effective length
rlen
of the string to assign as the smaller of
n and
str.size() - pos and calls
assign(str.data() + pos, rlen). template<class T>
basic_string& assign(const T& t);
Effects:
Equivalent to:
{
basic_string_view<charT, traits> sv = t;
return assign(sv.data(), sv.size());
}
Remarks:
This function shall not participate in overload resolution unless
is_convertible_v<const T&, basic_string_view<charT, traits>> is
true and
is_convertible_v<const T&, const charT*> is
false. template<class T>
basic_string& assign(const T& t, size_type pos, size_type n = npos);
Throws:
out_of_range
if
pos > sv.size(). Effects:
Creates a variable,
sv, as if by
basic_string_view<charT, traits> sv = t. Determines the effective length
rlen of the string to assign
as the smaller of
n and
sv.size() - pos
and calls
assign(sv.data() + pos, rlen).Remarks:
This function shall not participate in overload resolution
unless
is_convertible_v<const T&, basic_string_view<charT, traits>>
is
true and
is_convertible_v<const T&, const charT*> is
false. basic_string& assign(const charT* s, size_type n);
Requires: s points to an array of at least
n elements of
charT. Throws: length_error if
n > max_size(). Effects: Replaces the string controlled by
*this with a string
of length
n whose elements are a copy of those pointed to by
s. basic_string& assign(const charT* s);
Requires: s points to an array of at least
traits::length(s) + 1
elements of
charT. Effects: Calls
assign(s, traits::length(s)). basic_string& assign(initializer_list<charT> il);
Effects: Calls
assign(il.begin(), il.size()). basic_string& assign(size_type n, charT c);
Effects: Equivalent to: return assign(basic_string(n, c));
template<class InputIterator>
basic_string& assign(InputIterator first, InputIterator last);
Effects: Equivalent to: return assign(basic_string(first, last, get_allocator()));
basic_string& insert(size_type pos, const basic_string& str);
Effects: Equivalent to: return insert(pos, str.data(), str.size());
basic_string& insert(size_type pos1, const basic_string& str, size_type pos2, size_type n = npos);
Throws:
out_of_range
if
pos1 > size()
or
pos2 > str.size(). Effects:
Determines the effective length
rlen of the string to insert as the smaller
of
n and
str.size() - pos2 and calls
insert(pos1, str.data() + pos2, rlen). template<class T>
basic_string& insert(size_type pos, const T& t);
Effects:
Equivalent to:
{
basic_string_view<charT, traits> sv = t;
return insert(pos, sv.data(), sv.size());
}
Remarks:
This function shall not participate in overload resolution unless
is_convertible_v<const T&, basic_string_view<charT, traits>> is
true and
is_convertible_v<const T&, const charT*> is
false. template<class T>
basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n = npos);
Throws:
out_of_range
if
pos1 > size()
or
pos2 > sv.size(). Effects:
Creates a variable,
sv, as if by
basic_string_view<charT, traits> sv = t. Determines the effective length
rlen of the string to assign
as the smaller of
n and
sv.size() - pos2
and calls
insert(pos1, sv.data() + pos2, rlen).Remarks:
This function shall not participate in overload resolution
unless
is_convertible_v<const T&, basic_string_view<charT, traits>>
is
true and
is_convertible_v<const T&, const charT*> is
false. basic_string& insert(size_type pos, const charT* s, size_type n);
Requires: s points to an array of at least
n
elements of
charT. Throws: out_of_range if
pos > size() or
length_error
if
size() + n > max_size(). Effects: Replaces the string controlled by
*this with a string of
length
size() + n whose first
pos elements are a copy of
the initial elements of the original string controlled by
*this and
whose next
n elements are a copy of the elements in
s and
whose remaining elements are a copy of the remaining elements of the original
string controlled by
*this. basic_string& insert(size_type pos, const charT* s);
Requires: s points to an array of at least
traits::length(s) + 1 elements of
charT. Effects: Equivalent to: return insert(pos, s, traits::length(s));
basic_string& insert(size_type pos, size_type n, charT c);
Effects: Equivalent to: return insert(pos, basic_string(n, c));
iterator insert(const_iterator p, charT c);
Requires:
p is a valid iterator on
*this. Effects:
Inserts a copy of
c before the character referred to by
p. Returns:
An iterator which refers to the copy of the inserted character
. iterator insert(const_iterator p, size_type n, charT c);
Requires:
p is a valid iterator on
*this. Effects:
Inserts
n copies of
c before the character referred to by
p. Returns: An iterator which refers to the copy of the first inserted character, or
p if
n == 0. template<class InputIterator>
iterator insert(const_iterator p, InputIterator first, InputIterator last);
Requires:
p is a valid iterator on
*this. [first, last)
is a valid range
. Effects:
Equivalent to
insert(p - begin(), basic_string(first, last, get_allocator())). Returns: An iterator which refers to the copy of the first inserted character, or
p if
first == last. iterator insert(const_iterator p, initializer_list<charT> il);
Effects: As if by
insert(p, il.begin(), il.end()). Returns: An iterator which refers to the copy of the first inserted character, or
p if
i1 is empty
. basic_string& erase(size_type pos = 0, size_type n = npos);
Throws:
out_of_range
if
pos
> size(). Effects:
Determines the effective length
xlen
of the string to be removed as the smaller of
n and
size() - pos. The function then replaces the string controlled by
*this
with a string of length
size() - xlen
whose first
pos elements are a copy of the initial elements of the original string controlled by
*this,
and whose remaining elements are a copy of the elements of the original string controlled by
*this
beginning at position
pos + xlen.iterator erase(const_iterator p);
Effects:
Removes the character referred to by
p. 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
.iterator erase(const_iterator first, const_iterator last);
Requires:
first and
last are valid iterators on
*this,
defining a range
[first, last). Effects:
Removes the characters in the range
[first, last). 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
.Effects:
Equivalent to
erase(size() - 1, 1). basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
Effects: Equivalent to: return replace(pos1, n1, str.data(), str.size());
basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
size_type pos2, size_type n2 = npos);
Throws:
out_of_range
if
pos1 > size()
or
pos2 > str.size(). Effects:
Determines the effective length
rlen of the string to be inserted
as the smaller of
n2 and
str.size() - pos2 and calls
replace(pos1, n1, str.data() + pos2, rlen). template<class T>
basic_string& replace(size_type pos1, size_type n1, const T& t);
Effects:
Equivalent to:
{
basic_string_view<charT, traits> sv = t;
return replace(pos1, n1, sv.data(), sv.size());
}
Remarks:
This function shall not participate in overload resolution unless
is_convertible_v<const T&, basic_string_view<charT, traits>> is
true and
is_convertible_v<const T&, const charT*> is
false. template<class T>
basic_string& replace(size_type pos1, size_type n1, const T& t,
size_type pos2, size_type n2 = npos);
Throws:
out_of_range
if
pos1 > size()
or
pos2 > sv.size(). Effects:
Creates a variable,
sv, as if by
basic_string_view<charT, traits> sv = t. Determines the effective length
rlen of the string to be inserted
as the smaller of
n2 and
sv.size() - pos2
and calls
replace(pos1, n1, sv.data() + pos2, rlen).Remarks:
This function shall not participate in overload resolution
unless
is_convertible_v<const T&, basic_string_view<charT, traits>>
is
true and
is_convertible_v<const T&, const charT*> is
false. basic_string& replace(size_type pos1, size_type n1, const charT* s, size_type n2);
Requires: s points to an array of at
least
n2 elements of
charT. Throws: out_of_range if
pos1 > size() or
length_error
if the length of the resulting string would exceed
max_size() (see below)
. Effects: Determines the effective length
xlen of the string to be
removed as the smaller of
n1 and
size() - pos1. If
size() - xlen >= max_size() - n2 throws
length_error. Otherwise,
the function replaces the string controlled by *
this with a string of
length
size() - xlen + n2 whose first
pos1 elements are a copy
of the initial elements of the original string controlled by
*this,
whose next
n2 elements are a copy of the initial
n2 elements
of
s, and whose remaining elements are a copy of the elements of the
original string controlled by
*this beginning at position
pos + xlen.basic_string& replace(size_type pos, size_type n, const charT* s);
Requires: s points to an array of at least
traits::length(s) + 1 elements of
charT. Effects: Equivalent to: return replace(pos, n, s, traits::length(s));
basic_string& replace(size_type pos1, size_type n1, size_type n2, charT c);
Effects: Equivalent to: return replace(pos1, n1, basic_string(n2, c));
basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
Requires:
[begin(), i1) and
[i1, i2) are valid ranges
. Effects:
Calls
replace(i1 - begin(), i2 - i1, str). template<class T>
basic_string& replace(const_iterator i1, const_iterator i2, const T& t);
Requires:
[begin(), i1) and
[i1, i2) are valid ranges
. Effects:
Creates a variable,
sv, as if by
basic_string_view<charT, traits> sv = t; and then
calls
replace(i1 - begin(), i2 - i1, sv). Remarks:
This function shall not participate in overload resolution unless
is_convertible_v<const T&, basic_string_view<charT, traits>> is
true and
is_convertible_v<const T&, const charT*> is
false. basic_string& replace(const_iterator i1, const_iterator i2, const charT* s, size_type n);
Requires: [begin(), i1) and
[i1, i2) are valid ranges and
s points to an array of at least
n elements of
charT. Effects: Calls
replace(i1 - begin(), i2 - i1, s, n). basic_string& replace(const_iterator i1, const_iterator i2, const charT* s);
Requires: [begin(), i1) and
[i1, i2) are valid ranges and
s points to an array of at least
traits::length(s) + 1
elements of
charT. Effects: Calls
replace(i1 - begin(), i2 - i1, s, traits::length(s)). basic_string& replace(const_iterator i1, const_iterator i2, size_type n, charT c);
Requires: [begin(), i1) and
[i1, i2) are valid ranges
. Effects: Calls
replace(i1 - begin(), i2 - i1, basic_string(n, c)). template<class InputIterator>
basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
Requires: [begin(), i1),
[i1, i2) and
[j1, j2) are valid ranges
. Effects: Calls
replace(i1 - begin(), i2 - i1, basic_string(j1, j2, get_allocator())). basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<charT> il);
Requires: [begin(), i1) and
[i1, i2) are valid ranges
. Effects: Calls
replace(i1 - begin(), i2 - i1, il.begin(), il.size()). size_type copy(charT* s, size_type n, size_type pos = 0) const;
Let
rlen be the smaller of
n and
size() - pos.Throws:
out_of_range
if
pos > size(). Requires:
[s, s + rlen) is a valid range
. Effects:
Equivalent to
traits::copy(s, data() + pos, rlen). [
βNote: This does not terminate
s with a null object
. β
βend note β]
void swap(basic_string& s)
noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
allocator_traits<Allocator>::is_always_equal::value);
Ensures:
*this
contains the same sequence of characters that was in
s,
s contains the same sequence of characters that was in
*this. Complexity: Constant time
. const charT* c_str() const noexcept;
const charT* data() const noexcept;
Returns: A pointer
p such that
p + i == &operator[](i) for each
i in
[0, size()]. Complexity: Constant time
. Requires:
The program shall not alter any of the values stored in the character array
. Returns: A pointer
p such that
p + i == &operator[](i) for each
i in
[0, size()]. Complexity: Constant time
. Requires:
The program shall not alter the value stored at
p + size(). operator basic_string_view<charT, traits>() const noexcept;
Effects: Equivalent to:
return basic_string_view<charT, traits>(data(), size());
allocator_type get_allocator() const noexcept;
Returns:
A copy of the
Allocator
object used to construct the string or, if that allocator has been replaced, a
copy of the most recent replacement
. template<class T>
size_type find(const T& t, size_type pos = 0) const;
Effects:
Creates a variable,
sv, as if by
basic_string_view<charT, traits> sv = t; and then
determines the lowest position
xpos, if possible, such that both of
the following conditions hold:
Returns:
xpos if the function can determine such a value for
xpos. Remarks:
This function shall not participate in overload resolution unless
is_convertible_v<const T&, basic_string_view<charT, traits>> is
true and
is_convertible_v<const T&, const charT*> is
false. Throws:
Nothing unless the initialization of
sv throws an exception
. size_type find(const basic_string& str, size_type pos = 0) const noexcept;
Effects:
Equivalent to: return find(basic_string_view<charT, traits>(str), pos);
size_type find(const charT* s, size_type pos, size_type n) const;
Returns:
find(basic_string_view<charT, traits>(s, n), pos). size_type find(const charT* s, size_type pos = 0) const;
Requires: s points to an array of at least
traits::length(s) + 1
elements of
charT. Returns:
find(basic_string_view<charT, traits>(s), pos). size_type find(charT c, size_type pos = 0) const;
Returns:
find(basic_string(1, c), pos). template<class T>
size_type rfind(const T& t, size_type pos = npos) const;
Effects:
Creates a variable,
sv, as if by
basic_string_view<charT, traits> sv = t; and then
determines the highest position
xpos, if possible, such that both of
the following conditions hold:
Returns:
xpos if the function can determine such a value for
xpos. Remarks:
This function shall not participate in overload resolution unless
is_convertible_v<const T&, basic_string_view<charT, traits>> is
true and
is_convertible_v<const T&, const charT*> is
false. Throws:
Nothing unless the initialization of
sv throws an exception
. size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
Effects:
Equivalent to: return rfind(basic_string_view<charT, traits>(str), pos);
size_type rfind(const charT* s, size_type pos, size_type n) const;
Returns:
rfind(basic_string_view<charT, traits>(s, n), pos). size_type rfind(const charT* s, size_type pos = npos) const;
Requires: s points to an array of at least
traits::length(s) + 1
elements of
charT. Returns:
rfind(basic_string_view<charT, traits>(s), pos). size_type rfind(charT c, size_type pos = npos) const;
Returns:
rfind(basic_string(1, c), pos). template<class T>
size_type find_first_of(const T& t, size_type pos = 0) const;
Effects:
Creates a variable, sv, as if by
basic_string_view<charT, traits> sv = t; and then
determines the lowest position xpos, if possible, such that both of
the following conditions hold:
Returns:
xpos if the function can determine such a value for
xpos. Remarks:
This function shall not participate in overload resolution unless
is_convertible_v<const T&, basic_string_view<charT, traits>> is
true and
is_convertible_v<const T&, const charT*> is
false. Throws:
Nothing unless the initialization of
sv throws an exception
. size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
Effects:
Equivalent to: return find_first_of(basic_string_view<charT, traits>(str), pos);
size_type find_first_of(const charT* s, size_type pos, size_type n) const;
Returns:
find_first_of(basic_string_view<charT, traits>(s, n), pos). size_type find_first_of(const charT* s, size_type pos = 0) const;
Requires: s points to an array of at least
traits::length(s) + 1
elements of
charT. Returns:
find_first_of(basic_string_view<charT, traits>(s), pos). size_type find_first_of(charT c, size_type pos = 0) const;
Returns:
find_first_of(basic_string(1, c), pos). template<class T>
size_type find_last_of(const T& t, size_type pos = npos) const;
Effects:
Creates a variable,
sv, as if by
basic_string_view<charT, traits> sv = t; and then
determines the highest position
xpos, if possible, such that both of
the following conditions hold:
Remarks:
This function shall not participate in overload resolution unless
is_convertible_v<const T&, basic_string_view<charT, traits>> is
true and
is_convertible_v<const T&, const charT*> is
false. Throws:
Nothing unless the initialization of
sv throws an exception
. Returns:
xpos if the function can determine such a value for
xpos. size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
Effects:
Equivalent to: return find_last_of(basic_string_view<charT, traits>(str), pos);
size_type find_last_of(const charT* s, size_type pos, size_type n) const;
Returns:
find_last_of(basic_string_view<charT, traits>(s, n), pos). size_type find_last_of(const charT* s, size_type pos = npos) const;
Requires: s points to an array of at least
traits::length(s) + 1
elements of
charT. Returns:
find_last_of(basic_string_view<charT, traits>(s), pos). size_type find_last_of(charT c, size_type pos = npos) const;
Returns:
find_last_of(basic_string(1, c), pos). template<class T>
size_type find_first_not_of(const T& t, size_type pos = 0) const;
Effects:
Creates a variable,
sv, as if by
basic_string_view<charT, traits> sv = t; and then
determines the lowest position
xpos, if possible, such that both of
the following conditions hold:
Remarks:
This function shall not participate in overload resolution unless
is_convertible_v<const T&, basic_string_view<charT, traits>> is
true and
is_convertible_v<const T&, const charT*> is
false. Throws:
Nothing unless the initialization of
sv throws an exception
. Returns:
xpos if the function can determine such a value for
xpos. size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
Effects:
Equivalent to:
return find_first_not_of(basic_string_view<charT, traits>(str), pos);
size_type find_first_not_of(const charT* s, size_type pos, size_type n) const;
Returns:
find_first_not_of(basic_string_view<charT, traits>(s, n), pos). size_type find_first_not_of(const charT* s, size_type pos = 0) const;
Requires: s points to an array of at least
traits::length(s) + 1
elements of
charT. Returns:
find_first_not_of(basic_string_view<charT, traits>(s), pos). size_type find_first_not_of(charT c, size_type pos = 0) const;
Returns:
find_first_not_of(basic_string(1, c), pos). template<class T>
size_type find_last_not_of(const T& t, size_type pos = npos) const;
Effects:
Creates a variable,
sv, as if by
basic_string_view<charT, traits> sv = t; and then
determines the highest position
xpos, if possible, such that both of
the following conditions hold:
Remarks:
This function shall not participate in overload resolution unless
is_convertible_v<const T&, basic_string_view<charT, traits>> is
true and
is_convertible_v<const T&, const charT*> is
false. Throws:
Nothing unless the initialization of
sv throws an exception
. Returns:
xpos if the function can determine such a value for
xpos. size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
Effects:
Equivalent to:
return find_last_not_of(basic_string_view<charT, traits>(str), pos);
size_type find_last_not_of(const charT* s, size_type pos, size_type n) const;
Returns:
find_last_not_of(basic_string_view<charT, traits>(s, n), pos). size_type find_last_not_of(const charT* s, size_type pos = npos) const;
Requires: s points to an array of at least
traits::length(s) + 1
elements of
charT. Returns:
find_last_not_of(basic_string_view<charT, traits>(s), pos). size_type find_last_not_of(charT c, size_type pos = npos) const;
Returns:
find_last_not_of(basic_string(1, c), pos). basic_string substr(size_type pos = 0, size_type n = npos) const;
Throws:
out_of_range
if
pos > size(). Effects:
Determines the effective length
rlen of the string to copy as the smaller of
n and
size() - pos. Returns:
basic_string(data()+pos, rlen). template<class T>
int compare(const T& t) const;
Effects:
Creates a variable,
sv, as if by
basic_string_view<charT, traits> sv = t; and then
determines the effective length
rlen
of the strings to compare as the smaller of
size()
and
sv.size(). The function then compares the two strings by calling
traits::compare(data(), sv.data(), rlen).Returns:
The nonzero result if the result of the comparison is nonzero
. Otherwise, returns a value as indicated in Table
58.Table
58 β
compare() results
Condition | Return Value |
size() < sv.size() | < 0 |
size() == sv.size() | 0 |
size() > sv.size() | > 0 |
Remarks:
This function shall not participate in overload resolution unless
is_convertible_v<const T&, basic_string_view<charT, traits>> is
true and
is_convertible_v<const T&, const charT*> is
false. Throws:
Nothing unless the initialization of
sv throws an exception
. template<class T>
int compare(size_type pos1, size_type n1, const T& t) const;
Effects:
Equivalent to:
{
basic_string_view<charT, traits> sv = t;
return basic_string_view<charT, traits>(data(), size()).substr(pos1, n1).compare(sv);
}
Remarks:
This function shall not participate in overload resolution unless
is_convertible_v<const T&, basic_string_view<charT, traits>> is
true and
is_convertible_v<const T&, const charT*> is
false. template<class T>
int compare(size_type pos1, size_type n1, const T& t, size_type pos2, size_type n2 = npos) const;
Effects:
Equivalent to:
basic_string_view<charT, traits> sv = t;
return basic_string_view<charT, traits>(
data(), size()).substr(pos1, n1).compare(sv.substr(pos2, n2));
Remarks:
This function shall not participate in overload resolution
unless
is_convertible_v<const T&, basic_string_view<charT, traits>>
is
true and
is_convertible_v<const T&, const charT*> is
false. int compare(const basic_string& str) const noexcept;
Effects:
Equivalent to:
return compare(basic_string_view<charT, traits>(str));
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));
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);
int compare(const charT* s) const;
Returns:
compare(basic_string(s)). int compare(size_type pos, size_type n1, const charT* s) const;
Returns: basic_string(*this, pos, n1).compare(basic_string(s)). int compare(size_type pos, size_type n1, const charT* s, size_type n2) const;
Returns: basic_string(*this, pos, n1).compare(basic_string(s, n2)). bool starts_with(basic_string_view<charT, traits> x) const noexcept;
bool starts_with(charT x) const noexcept;
bool starts_with(const charT* x) const;
Effects:
Equivalent to:
return basic_string_view<charT, traits>(data(), size()).starts_with(x);
bool ends_with(basic_string_view<charT, traits> x) const noexcept;
bool ends_with(charT x) const noexcept;
bool ends_with(const charT* x) const;
Effects:
Equivalent to:
return basic_string_view<charT, traits>(data(), size()).ends_with(x);