24 Strings library [strings]

24.4 String view classes [string.view]

24.4.2 Class template basic_­string_­view [string.view.template]

24.4.2.6 String operations [string.view.ops]

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

Позвольте rlen быть меньшим из n и size() - pos.

Throws: out_­of_­range если pos > size().

Requires: [s, s + rlen) допустимый диапазон.

Effects: Эквивалентно traits​::​copy(s, data() + pos, rlen).

Returns: rlen.

Complexity: O(rlen).

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

Позвольте rlen быть меньшим из n и size() - pos.

Throws: out_­of_­range если pos > size().

Effects: Определяет rlenэффективную длину строки для ссылки.

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

constexpr int compare(basic_string_view str) const noexcept;

Позвольте rlen быть меньшим из size() и str.size().

Effects: Определяет rlenэффективную длину сравниваемых строк. Затем функция сравнивает две строки, вызывая traits​::​compare(data(), str.data(), rlen).

Complexity: O(rlen).

Returns: Ненулевой результат, если результат сравнения отличен от нуля. В противном случае возвращает значение, указанное в таблице 66.

Таблица 66 - compare() результаты
СостояниеВозвращаемое значение
size() < str.size() < 0
size() == str.size()  0
size() > str.size() > 0

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

Effects: Эквивалентен: return substr(pos1, n1).compare(str);

constexpr int compare(size_type pos1, size_type n1, basic_string_view str, size_type pos2, size_type n2) const;

Effects: Эквивалентен: return substr(pos1, n1).compare(str.substr(pos2, n2));

constexpr int compare(const charT* s) const;

Effects: Эквивалентен: return compare(basic_­string_­view(s));

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

Effects: Эквивалентен: return substr(pos1, n1).compare(basic_­string_­view(s));

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

Effects: Эквивалентен: return substr(pos1, n1).compare(basic_­string_­view(s, n2));