template<class charT, class traits = char_traits<charT>> class basic_string_view { public: // types using traits_type = traits; using value_type = charT; using pointer = value_type*; using const_pointer = const value_type*; using reference = value_type&; using const_reference = const value_type&; using const_iterator = implementation-defined; // see [string.view.iterators] using iterator = const_iterator;228 using const_reverse_iterator = reverse_iterator<const_iterator>; using reverse_iterator = const_reverse_iterator; using size_type = size_t; using difference_type = ptrdiff_t; static constexpr size_type npos = size_type(-1); // [string.view.cons], construction and assignment constexpr basic_string_view() noexcept; constexpr basic_string_view(const basic_string_view&) noexcept = default; constexpr basic_string_view& operator=(const basic_string_view&) noexcept = default; constexpr basic_string_view(const charT* str); constexpr basic_string_view(const charT* str, size_type len); // [string.view.iterators], iterator support constexpr const_iterator begin() const noexcept; constexpr const_iterator end() const noexcept; constexpr const_iterator cbegin() const noexcept; constexpr const_iterator cend() const noexcept; constexpr const_reverse_iterator rbegin() const noexcept; constexpr const_reverse_iterator rend() const noexcept; constexpr const_reverse_iterator crbegin() const noexcept; constexpr const_reverse_iterator crend() const noexcept; // [string.view.capacity], capacity constexpr size_type size() const noexcept; constexpr size_type length() const noexcept; constexpr size_type max_size() const noexcept; constexpr bool empty() const noexcept; // [string.view.access], element access constexpr const_reference operator[](size_type pos) const; constexpr const_reference at(size_type pos) const; constexpr const_reference front() const; constexpr const_reference back() const; constexpr const_pointer data() const noexcept; // [string.view.modifiers], modifiers constexpr void remove_prefix(size_type n); constexpr void remove_suffix(size_type n); constexpr void swap(basic_string_view& s) noexcept; // [string.view.ops], string operations size_type copy(charT* s, size_type n, size_type pos = 0) const; constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const; constexpr int compare(basic_string_view s) const noexcept; constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const; constexpr int compare(size_type pos1, size_type n1, basic_string_view s, size_type pos2, size_type n2) 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 size_type find(basic_string_view s, size_type pos = 0) const noexcept; constexpr size_type find(charT c, 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 rfind(basic_string_view s, size_type pos = npos) const noexcept; constexpr size_type rfind(charT c, 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 find_first_of(basic_string_view s, size_type pos = 0) const noexcept; constexpr size_type find_first_of(charT c, 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_last_of(basic_string_view s, size_type pos = npos) const noexcept; constexpr size_type find_last_of(charT c, 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_first_not_of(basic_string_view s, size_type pos = 0) const noexcept; constexpr size_type find_first_not_of(charT c, 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_last_not_of(basic_string_view s, size_type pos = npos) const noexcept; constexpr size_type find_last_not_of(charT c, 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; private: const_pointer data_; // exposition only size_type size_; // exposition only };
В каждой специализацииbasic_string_view<charT, traits>типtraits должен удовлетворять требованиям к характеристикам символов ([char.traits]), и типtraits::char_type должен называть тот же тип, что иcharT.
Потому чтоbasic_string_view относится к постоянной последовательностиiterator иconst_iterator относятся к одному типу.
constexpr basic_string_view() noexcept;
constexpr basic_string_view(const charT* str);
constexpr basic_string_view(const charT* str, size_type len);
using const_iterator = implementation-defined;
Тип, отвечающий требованиям постоянного итератора произвольного доступа ([random.access.iterators]) и непрерывного итератора ([iterator.requirements.general]), которыйvalue_type является параметром шаблонаcharT.
Для abasic_string_view strлюбая операция, которая делает недействительным указатель в диапазоне,[str.data(), str.data() + str.size()) делает недействительными указатели, итераторы и ссылки, возвращаемые изstrметодов.
Все требования к контейнерным итераторам ([container.requirements]) также применимыbasic_string_view::const_iterator .
constexpr const_iterator begin() const noexcept;
constexpr const_iterator cbegin() const noexcept;
constexpr const_iterator end() const noexcept;
constexpr const_iterator cend() const noexcept;
constexpr const_reverse_iterator rbegin() const noexcept;
constexpr const_reverse_iterator crbegin() const noexcept;
constexpr const_reverse_iterator rend() const noexcept;
constexpr const_reverse_iterator crend() const noexcept;
constexpr size_type size() const noexcept;
constexpr size_type length() const noexcept;
constexpr size_type max_size() const noexcept;
Returns: Максимально возможное количество символьных объектов, на которые может ссылаться abasic_string_view.
constexpr bool empty() const noexcept;
constexpr const_reference operator[](size_type pos) const;
[ Note: В отличие отbasic_string::operator[], basic_string_view::operator[](size()) имеет неопределенное поведение вместо возвратаcharT(). ] — end note
constexpr const_reference at(size_type pos) const;
constexpr const_reference front() const;
constexpr const_reference back() const;
constexpr const_pointer data() const noexcept;
constexpr void remove_prefix(size_type n);
constexpr void remove_suffix(size_type n);
constexpr void swap(basic_string_view& s) noexcept;
size_type copy(charT* s, size_type n, size_type pos = 0) const;
constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
constexpr int compare(basic_string_view str) const noexcept;
Effects: Определяетrlenэффективную длину сравниваемых строк. Затем функция сравнивает две строки, вызываяtraits::compare(data(), str.data(), rlen).
constexpr int compare(size_type pos1, size_type n1, basic_string_view str) const;
constexpr int compare(size_type pos1, size_type n1, basic_string_view str,
size_type pos2, size_type n2) 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;
В этом разделе описываютсяbasic_string_view функции - члены с именем find,rfind,find_first_of,find_last_of,find_first_not_of, иfind_last_not_of.
Функции-члены в этом разделеO(size() * str.size()) в худшем случае сложны, хотя реализациям рекомендуется работать лучше.
Каждая функция-член формы
constexpr return-type F(const charT* s, size_type pos);
эквивалентноreturn F(basic_string_view(s), pos);
Каждая функция-член формы
constexpr return-type F(const charT* s, size_type pos, size_type n);
эквивалентноreturn F(basic_string_view(s, n), pos);
Каждая функция-член формы
constexpr return-type F(charT c, size_type pos);
эквивалентноreturn F(basic_string_view(&c, 1), pos);
constexpr size_type find(basic_string_view str, size_type pos = 0) const noexcept;
Returns: xpos если функция может определить такое значение дляxpos. В противном случае возвращаетсяnpos.
constexpr size_type rfind(basic_string_view str, size_type pos = npos) const noexcept;
Returns: xpos если функция может определить такое значение дляxpos. В противном случае возвращаетсяnpos.
constexpr size_type find_first_of(basic_string_view str, size_type pos = 0) const noexcept;
Returns: xpos если функция может определить такое значение дляxpos. В противном случае возвращаетсяnpos.
constexpr size_type find_last_of(basic_string_view str, size_type pos = npos) const noexcept;
Returns: xpos если функция может определить такое значение дляxpos. В противном случае возвращаетсяnpos.
constexpr size_type find_first_not_of(basic_string_view str, size_type pos = 0) const noexcept;
Returns: xpos если функция может определить такое значение дляxpos. В противном случае возвращаетсяnpos.
constexpr size_type find_last_not_of(basic_string_view str, size_type pos = npos) const noexcept;