24 Strings library [strings]

24.3 String classes [string.classes]

24.3.3 basic_­string non-member functions [string.nonmembers]

24.3.3.1 operator+ [string.op+]

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

Returns: basic_­string<charT, traits, Allocator>(lhs).append(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);

Returns: std​::​move(lhs.append(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);

Returns: std​::​move(rhs.insert(0, lhs)).

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

Returns: std​::​move(lhs.append(rhs)). [ Note: Или то же самое,std​::​move(rhs.insert(0, lhs)). ] end note

template<class charT, class traits, class Allocator> basic_string<charT, traits, Allocator> operator+(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs);

Returns: basic_­string<charT, traits, Allocator>(lhs) + rhs.

Remarks: Использует traits​::​length().

template<class charT, class traits, class Allocator> basic_string<charT, traits, Allocator> operator+(const charT* lhs, basic_string<charT, traits, Allocator>&& rhs);

Returns: std​::​move(rhs.insert(0, lhs)).

Remarks: Использует traits​::​length().

template<class charT, class traits, class Allocator> basic_string<charT, traits, Allocator> operator+(charT lhs, const basic_string<charT, traits, Allocator>& rhs);

Returns: basic_­string<charT, traits, Allocator>(1, lhs) + rhs.

template<class charT, class traits, class Allocator> basic_string<charT, traits, Allocator> operator+(charT lhs, basic_string<charT, traits, Allocator>&& rhs);

Returns: std​::​move(rhs.insert(0, 1, lhs)).

template<class charT, class traits, class Allocator> basic_string<charT, traits, Allocator> operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);

Returns: lhs + basic_­string<charT, traits, Allocator>(rhs).

Remarks: Использует traits​::​length().

template<class charT, class traits, class Allocator> basic_string<charT, traits, Allocator> operator+(basic_string<charT, traits, Allocator>&& lhs, const charT* rhs);

Returns: std​::​move(lhs.append(rhs)).

Remarks: Использует traits​::​length().

template<class charT, class traits, class Allocator> basic_string<charT, traits, Allocator> operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);

Returns: lhs + basic_­string<charT, traits, Allocator>(1, rhs).

template<class charT, class traits, class Allocator> basic_string<charT, traits, Allocator> operator+(basic_string<charT, traits, Allocator>&& lhs, charT rhs);

Returns: std​::​move(lhs.append(1, rhs)).

24.3.3.2 operator== [string.operator==]

template<class charT, class traits, class Allocator> bool operator==(const basic_string<charT, traits, Allocator>& lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;

Returns: lhs.compare(rhs) == 0.

template<class charT, class traits, class Allocator> bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs);

Returns: rhs == lhs.

template<class charT, class traits, class Allocator> bool operator==(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);

Requires:rhs указывает на массив, состоящий как минимум изtraits​::​length(rhs) + 1 элементовcharT.

Returns: lhs.compare(rhs) == 0.

24.3.3.3 operator!= [string.op!=]

template<class charT, class traits, class Allocator> bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;

Returns: !(lhs == rhs).

template<class charT, class traits, class Allocator> bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs);

Returns: rhs != lhs.

template<class charT, class traits, class Allocator> bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);

Requires:rhs указывает на массив, состоящий как минимум изtraits​::​length(rhs) + 1 элементовcharT.

Returns: lhs.compare(rhs) != 0.

24.3.3.4 operator< [string.op<]

template<class charT, class traits, class Allocator> bool operator< (const basic_string<charT, traits, Allocator>& lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;

Returns: lhs.compare(rhs) < 0.

template<class charT, class traits, class Allocator> bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs);

Returns: rhs.compare(lhs) > 0.

template<class charT, class traits, class Allocator> bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);

Returns: lhs.compare(rhs) < 0.

24.3.3.5 operator> [string.op>]

template<class charT, class traits, class Allocator> bool operator> (const basic_string<charT, traits, Allocator>& lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;

Returns: lhs.compare(rhs) > 0.

template<class charT, class traits, class Allocator> bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs);

Returns: rhs.compare(lhs) < 0.

template<class charT, class traits, class Allocator> bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);

Returns: lhs.compare(rhs) > 0.

24.3.3.6 operator<= [string.op<=]

template<class charT, class traits, class Allocator> bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;

Returns: lhs.compare(rhs) <= 0.

template<class charT, class traits, class Allocator> bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs);

Returns: rhs.compare(lhs) >= 0.

template<class charT, class traits, class Allocator> bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);

Returns: lhs.compare(rhs) <= 0.

24.3.3.7 operator>= [string.op>=]

template<class charT, class traits, class Allocator> bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;

Returns: lhs.compare(rhs) >= 0.

template<class charT, class traits, class Allocator> bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs);

Returns: rhs.compare(lhs) <= 0.

template<class charT, class traits, class Allocator> bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);

Returns: lhs.compare(rhs) >= 0.

24.3.3.8 swap [string.special]

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

Effects: Эквивалентен:lhs.swap(rhs);

24.3.3.9 Inserters and extractors [string.io]

template<class charT, class traits, class Allocator> basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);

Effects: Ведет себя какformatted input function. После создания sentry объекта, если часовой преобразуется вtrue, вызывает, str.erase() а затем извлекает символы изis и добавляет их,str как если бы, вызывая str.append(1, c). Если is.width() больше нуля, максимальное количествоn добавляемых символов is.width(): в противном случаеn это str.max_­size(). Символы извлекаются и добавляются до тех пор, пока не произойдет одно из следующих событий:

  • n символы сохраняются;

  • конец файла встречается во входной последовательности;

  • isspace(c, is.getloc()) являетсяtrue для следующего доступного входного символа c.

После извлечения последнего символа (если есть) вызывается is.width(0) и sentry объект уничтожается.

Если функция не извлекает символы, она вызывает is.setstate(ios​::​failbit), что может вызвать throw ios_­base​::​failure ([iostate.flags]).

Returns: is.

template<class charT, class traits, class Allocator> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);

Effects: Эквивалентен:return os << basic_­string_­view<charT, traits>(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);

Effects: Ведет себя как объектunformatted input function, за исключением того, что не влияет на значение, возвращаемое при последующих вызовах basic_­istream<>​::​gcount(). После создания sentry объекта, если часовой преобразуется вtrue, вызывает, str.erase() а затем извлекает символыis и добавляет их,str как если бы, вызывая str.append(1, c) до тех пор, пока не произойдет одно из следующих событий:

  • конец файла происходит во входной последовательности (в этом случае getline вызывается функция is.setstate(​ios_­base​::​eofbit)).

  • traits​::​eq(c, delim) для следующего доступного входного символа c (в этом случае c извлекается, но не добавляется) ([iostate.flags])

  • str.max_­size() символы сохраняются (в этом случае функция calls is.setstate(ios_­base​::​failbit)) ([iostate.flags])

Условия проверяются в указанном порядке. В любом случае после извлечения последнего символа sentry объект уничтожается.

Если функция не извлекает символы, она вызывает is.setstate(ios_­base​::​failbit) which may throw ios_­base​::​failure ([iostate.flags]).

Returns: is.

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

Returns: getline(is, str, is.widen('\n')).