[string.view.template]

# 27 Strings library [[strings]](./#strings)

## 27.3 String view classes [[string.view]](string.view#template)

### 27.3.3 Class template basic_string_view [string.view.template]

#### [27.3.3.1](#general) General [[string.view.template.general]](string.view.template.general)

[ð](#lib:basic_string_view)

namespace std {template<class charT, class traits = char_traits<charT>>class basic_string_view {public:// typesusing 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]](#string.view.iterators "27.3.3.4 Iterator support")using iterator = const_iterator;[211](#footnote-211 "Because basic_­string_­view refers to a constant sequence, iterator and const_­iterator are the same type.")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]](#string.view.cons "27.3.3.2 Construction and assignment"), construction and assignmentconstexpr 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);
 basic_string_view(nullptr_t) = delete; constexpr basic_string_view(const charT* str, size_type len); template<class It, class End>constexpr basic_string_view(It begin, End end); template<class R>constexpr explicit basic_string_view(R&& r); // [[string.view.iterators]](#string.view.iterators "27.3.3.4 Iterator support"), iterator supportconstexpr 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]](#string.view.capacity "27.3.3.5 Capacity"), capacityconstexpr 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]](#string.view.access "27.3.3.6 Element access"), element accessconstexpr const_reference operator[](size_type pos) const; constexpr const_reference at(size_type pos) const; // freestanding-deletedconstexpr const_reference front() const; constexpr const_reference back() const; constexpr const_pointer data() const noexcept; // [[string.view.modifiers]](#string.view.modifiers "27.3.3.7 Modifiers"), modifiersconstexpr 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.view.ops "27.3.3.8 String operations"), string operationsconstexpr size_type copy(charT* s, size_type n,
 size_type pos = 0) const; // freestanding-deletedconstexpr basic_string_view substr(size_type pos = 0,
 size_type n = npos) const; // freestanding-deletedconstexpr basic_string_view subview(size_type pos = 0,
 size_type n = npos) const; // freestanding-deletedconstexpr int compare(basic_string_view s) const noexcept; constexpr int compare(size_type pos1, size_type n1,
 basic_string_view s) const; // freestanding-deletedconstexpr int compare(size_type pos1, size_type n1, basic_string_view s,
 size_type pos2, size_type n2) const; // freestanding-deletedconstexpr int compare(const charT* s) const; constexpr int compare(size_type pos1, size_type n1, const charT* s) const; // freestanding-deletedconstexpr int compare(size_type pos1, size_type n1, const charT* s,
 size_type n2) const; // freestanding-deletedconstexpr bool starts_with(basic_string_view x) const noexcept; constexpr bool starts_with(charT x) const noexcept; constexpr bool starts_with(const charT* x) const; constexpr bool ends_with(basic_string_view x) const noexcept; constexpr bool ends_with(charT x) const noexcept; constexpr bool ends_with(const charT* x) const; constexpr bool contains(basic_string_view x) const noexcept; constexpr bool contains(charT x) const noexcept; constexpr bool contains(const charT* x) const; // [[string.view.find]](#string.view.find "27.3.3.9 Searching"), searchingconstexpr 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*}; // [[string.view.deduct]](#string.view.deduct "27.3.3.3 Deduction guides"), deduction guidestemplate<class It, class End> basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>; template<class R> basic_string_view(R&&) -> basic_string_view<ranges::range_value_t<R>>;}

[1](#general-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L749)

In every specialization basic_string_view<charT, traits>, the type traits shall meet the character traits requirements ([[char.traits]](char.traits "27.2 Character traits"))[.](#general-1.sentence-1)

[*Note [1](#general-note-1)*:

The program is ill-formed if traits​::​char_type is not the same type as charT[.](#general-1.sentence-2)

â *end note*]

[2](#general-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L755)

For a basic_string_view str,
any operation that invalidates a pointer
in the range[str.data(), str.data() + str.size()) invalidates pointers, iterators, and references
to elements of str[.](#general-2.sentence-1)

[3](#general-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L765)

The complexity of basic_string_view member functions is O(1) unless otherwise specified[.](#general-3.sentence-1)

[4](#general-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L769)

basic_string_view<charT, traits> is
a trivially copyable type ([[basic.types.general]](basic.types.general#term.trivially.copyable.type "6.9.1 General"))[.](#general-4.sentence-1)

[211)](#footnote-211)[211)](#footnoteref-211)

Because basic_string_view refers to a constant sequence, iterator and const_iterator are the same type[.](#footnote-211.sentence-1)

#### [27.3.3.2](#string.view.cons) Construction and assignment [[string.view.cons]](string.view.cons)

[ð](#lib:basic_string_view,constructor)

`constexpr basic_string_view() noexcept;
`

[1](#string.view.cons-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L781)

*Postconditions*: *size_* == 0 and *data_* == nullptr[.](#string.view.cons-1.sentence-1)

[ð](#lib:basic_string_view,constructor_)

`constexpr basic_string_view(const charT* str);
`

[2](#string.view.cons-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L792)

*Preconditions*: [str, str + traits​::​length(str)) is a valid range[.](#string.view.cons-2.sentence-1)

[3](#string.view.cons-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L796)

*Effects*: Constructs a basic_string_view, initializing *data_* with str and initializing *size_* with traits​::​length(str)[.](#string.view.cons-3.sentence-1)

[4](#string.view.cons-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L801)

*Complexity*: O(traits::length(str))[.](#string.view.cons-4.sentence-1)

[ð](#lib:basic_string_view,constructor__)

`constexpr basic_string_view(const charT* str, size_type len);
`

[5](#string.view.cons-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L812)

*Preconditions*: [str, str + len) is a valid range[.](#string.view.cons-5.sentence-1)

[6](#string.view.cons-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L816)

*Effects*: Constructs a basic_string_view, initializing *data_* with str and initializing *size_* with len[.](#string.view.cons-6.sentence-1)

[ð](#lib:basic_string_view,constructor___)

`template<class It, class End>
  constexpr basic_string_view(It begin, End end);
`

[7](#string.view.cons-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L829)

*Constraints*: 

- [(7.1)](#string.view.cons-7.1)

  It satisfies [contiguous_iterator](iterator.concept.contiguous#concept:contiguous_iterator "24.3.4.14 Concept contiguous_­iterator [iterator.concept.contiguous]")[.](#string.view.cons-7.1.sentence-1)

- [(7.2)](#string.view.cons-7.2)

  End satisfies [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]")<It>[.](#string.view.cons-7.2.sentence-1)

- [(7.3)](#string.view.cons-7.3)

  is_same_v<iter_value_t<It>, charT> is true[.](#string.view.cons-7.3.sentence-1)

- [(7.4)](#string.view.cons-7.4)

  is_convertible_v<End, size_type> is false[.](#string.view.cons-7.4.sentence-1)

[8](#string.view.cons-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L838)

*Preconditions*: 

- [(8.1)](#string.view.cons-8.1)

  [begin, end) is a valid range[.](#string.view.cons-8.1.sentence-1)

- [(8.2)](#string.view.cons-8.2)

  It models [contiguous_iterator](iterator.concept.contiguous#concept:contiguous_iterator "24.3.4.14 Concept contiguous_­iterator [iterator.concept.contiguous]")[.](#string.view.cons-8.2.sentence-1)

- [(8.3)](#string.view.cons-8.3)

  End models [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]")<It>[.](#string.view.cons-8.3.sentence-1)

[9](#string.view.cons-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L846)

*Effects*: Initializes *data_* with to_address(begin) and
initializes *size_* with end - begin[.](#string.view.cons-9.sentence-1)

[10](#string.view.cons-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L851)

*Throws*: When and what end - begin throws[.](#string.view.cons-10.sentence-1)

[ð](#lib:basic_string_view,constructor____)

`template<class R>
  constexpr explicit basic_string_view(R&& r);
`

[11](#string.view.cons-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L863)

Let d be an lvalue of type remove_cvref_t<R>[.](#string.view.cons-11.sentence-1)

[12](#string.view.cons-12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L866)

*Constraints*: 

- [(12.1)](#string.view.cons-12.1)

remove_cvref_t<R> is not the same type as basic_string_view,

- [(12.2)](#string.view.cons-12.2)

R modelsranges​::​[contiguous_range](range.refinements#concept:contiguous_range "25.4.6 Other range refinements [range.refinements]") and ranges​::​[sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]"),

- [(12.3)](#string.view.cons-12.3)

is_same_v<ranges​::​range_value_t<R>, charT> is true,

- [(12.4)](#string.view.cons-12.4)

is_convertible_v<R, const charT*> is false, and

- [(12.5)](#string.view.cons-12.5)

d.operator ​::​std​::​basic_string_view<charT, traits>() is not a valid expression[.](#string.view.cons-12.sentence-1)

[13](#string.view.cons-13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L883)

*Effects*: Initializes *data_* with ranges​::​data(r) and*size_* with ranges​::​size(r)[.](#string.view.cons-13.sentence-1)

[14](#string.view.cons-14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L888)

*Throws*: Any exception thrown by ranges​::​data(r) and ranges​::​size(r)[.](#string.view.cons-14.sentence-1)

#### [27.3.3.3](#string.view.deduct) Deduction guides [[string.view.deduct]](string.view.deduct)

[ð](#string.view.deduct-itemdecl:1)

`template<class It, class End>
  basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>;
`

[1](#string.view.deduct-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L901)

*Constraints*: 

- [(1.1)](#string.view.deduct-1.1)

  It satisfies [contiguous_iterator](iterator.concept.contiguous#concept:contiguous_iterator "24.3.4.14 Concept contiguous_­iterator [iterator.concept.contiguous]")[.](#string.view.deduct-1.1.sentence-1)

- [(1.2)](#string.view.deduct-1.2)

  End satisfies [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]")<It>[.](#string.view.deduct-1.2.sentence-1)

[ð](#string.view.deduct-itemdecl:2)

`template<class R>
  basic_string_view(R&&) -> basic_string_view<ranges::range_value_t<R>>;
`

[2](#string.view.deduct-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L915)

*Constraints*: R satisfies ranges​::​[contiguous_range](range.refinements#concept:contiguous_range "25.4.6 Other range refinements [range.refinements]")[.](#string.view.deduct-2.sentence-1)

#### [27.3.3.4](#string.view.iterators) Iterator support [[string.view.iterators]](string.view.iterators)

[ð](#lib:const_iterator,basic_string_view_)

`using const_iterator = implementation-defined;
`

[1](#string.view.iterators-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L928)

A type that meets the requirements
of a constant[*Cpp17RandomAccessIterator*](random.access.iterators#:Cpp17RandomAccessIterator "24.3.5.7 Random access iterators [random.access.iterators]") ([[random.access.iterators]](random.access.iterators "24.3.5.7 Random access iterators")),
models [contiguous_iterator](iterator.concept.contiguous#concept:contiguous_iterator "24.3.4.14 Concept contiguous_­iterator [iterator.concept.contiguous]") ([[iterator.concept.contiguous]](iterator.concept.contiguous "24.3.4.14 Concept contiguous_­iterator")), and
meets the constexpr iterator requirements ([[iterator.requirements.general]](iterator.requirements.general "24.3.1 General")),
whose value_type is the template parameter charT[.](#string.view.iterators-1.sentence-1)

[2](#string.view.iterators-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L936)

All requirements on container iterators ([[container.requirements]](container.requirements "23.2 Requirements")) apply to basic_string_view​::​const_iterator as well[.](#string.view.iterators-2.sentence-1)

[ð](#lib:begin,basic_string_view)

`constexpr const_iterator begin() const noexcept;
constexpr const_iterator cbegin() const noexcept;
`

[3](#string.view.iterators-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L948)

*Returns*: An iterator such that

- [(3.1)](#string.view.iterators-3.1)

if !empty(), addressof(*begin()) == *data_*,

- [(3.2)](#string.view.iterators-3.2)

otherwise, an unspecified value such that [begin(), end()) is a valid range[.](#string.view.iterators-3.sentence-1)

[ð](#lib:end,basic_string_view)

`constexpr const_iterator end() const noexcept;
constexpr const_iterator cend() const noexcept;
`

[4](#string.view.iterators-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L965)

*Returns*: begin() + size()[.](#string.view.iterators-4.sentence-1)

[ð](#lib:rbegin,basic_string_view)

`constexpr const_reverse_iterator rbegin() const noexcept;
constexpr const_reverse_iterator crbegin() const noexcept;
`

[5](#string.view.iterators-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L978)

*Returns*: const_reverse_iterator(end())[.](#string.view.iterators-5.sentence-1)

[ð](#lib:rend,basic_string_view)

`constexpr const_reverse_iterator rend() const noexcept;
constexpr const_reverse_iterator crend() const noexcept;
`

[6](#string.view.iterators-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L991)

*Returns*: const_reverse_iterator(begin())[.](#string.view.iterators-6.sentence-1)

#### [27.3.3.5](#string.view.capacity) Capacity [[string.view.capacity]](string.view.capacity)

[ð](#lib:size,basic_string_view)

`constexpr size_type size() const noexcept;
constexpr size_type length() const noexcept;
`

[1](#string.view.capacity-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1006)

*Returns*: *size_*[.](#string.view.capacity-1.sentence-1)

[ð](#lib:max_size,basic_string_view)

`constexpr size_type max_size() const noexcept;
`

[2](#string.view.capacity-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1018)

*Returns*: The largest possible number of char-like objects that can be referred to by a basic_string_view[.](#string.view.capacity-2.sentence-1)

[ð](#lib:empty,basic_string_view)

`constexpr bool empty() const noexcept;
`

[3](#string.view.capacity-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1029)

*Returns*: *size_* == 0[.](#string.view.capacity-3.sentence-1)

#### [27.3.3.6](#string.view.access) Element access [[string.view.access]](string.view.access)

[ð](#lib:operator%5b%5d,basic_string_view)

`constexpr const_reference operator[](size_type pos) const;
`

[1](#string.view.access-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1042)

*Hardened preconditions*: pos < size() is true[.](#string.view.access-1.sentence-1)

[*Note [1](#string.view.access-note-1)*:

This precondition is stronger than the one on basic_string​::​operator[][.](#string.view.access-1.sentence-2)

â *end note*]

[2](#string.view.access-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1049)

*Returns*: *data_*[pos][.](#string.view.access-2.sentence-1)

[3](#string.view.access-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1053)

*Throws*: Nothing[.](#string.view.access-3.sentence-1)

[ð](#lib:at,basic_string_view)

`constexpr const_reference at(size_type pos) const;
`

[4](#string.view.access-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1064)

*Returns*: *data_*[pos][.](#string.view.access-4.sentence-1)

[5](#string.view.access-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1068)

*Throws*: out_of_range if pos >= size()[.](#string.view.access-5.sentence-1)

[ð](#lib:front,basic_string_view)

`constexpr const_reference front() const;
`

[6](#string.view.access-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1079)

*Hardened preconditions*: empty() is false[.](#string.view.access-6.sentence-1)

[7](#string.view.access-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1083)

*Returns*: *data_*[0][.](#string.view.access-7.sentence-1)

[8](#string.view.access-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1087)

*Throws*: Nothing[.](#string.view.access-8.sentence-1)

[ð](#lib:back,basic_string_view)

`constexpr const_reference back() const;
`

[9](#string.view.access-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1098)

*Hardened preconditions*: empty() is false[.](#string.view.access-9.sentence-1)

[10](#string.view.access-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1102)

*Returns*: *data_*[size() - 1][.](#string.view.access-10.sentence-1)

[11](#string.view.access-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1106)

*Throws*: Nothing[.](#string.view.access-11.sentence-1)

[ð](#lib:data,basic_string_view)

`constexpr const_pointer data() const noexcept;
`

[12](#string.view.access-12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1117)

*Returns*: *data_*[.](#string.view.access-12.sentence-1)

[13](#string.view.access-13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1121)

[*Note [2](#string.view.access-note-2)*:

Unlike basic_string​::​data() and [*string-literal*](lex.string#nt:string-literal "5.13.5 String literals [lex.string]")*s*,data() can return a pointer to a buffer that is not null-terminated[.](#string.view.access-13.sentence-1)

Therefore it is typically a mistake to pass data() to a function that takes just a const charT* and expects a null-terminated string[.](#string.view.access-13.sentence-2)

â *end note*]

#### [27.3.3.7](#string.view.modifiers) Modifiers [[string.view.modifiers]](string.view.modifiers)

[ð](#lib:remove_prefix,basic_string_view)

`constexpr void remove_prefix(size_type n);
`

[1](#string.view.modifiers-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1137)

*Hardened preconditions*: n <= size() is true[.](#string.view.modifiers-1.sentence-1)

[2](#string.view.modifiers-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1141)

*Effects*: Equivalent to: *data_* += n; *size_* -= n;

[ð](#lib:remove_suffix,basic_string_view)

`constexpr void remove_suffix(size_type n);
`

[3](#string.view.modifiers-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1152)

*Hardened preconditions*: n <= size() is true[.](#string.view.modifiers-3.sentence-1)

[4](#string.view.modifiers-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1156)

*Effects*: Equivalent to: *size_* -= n;

[ð](#lib:swap,basic_string_view)

`constexpr void swap(basic_string_view& s) noexcept;
`

[5](#string.view.modifiers-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1167)

*Effects*: Exchanges the values of *this and s[.](#string.view.modifiers-5.sentence-1)

#### [27.3.3.8](#string.view.ops) String operations [[string.view.ops]](string.view.ops)

[ð](#lib:copy,basic_string_view)

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

[1](#string.view.ops-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1180)

Let rlen be the smaller of n and size() - pos[.](#string.view.ops-1.sentence-1)

[2](#string.view.ops-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1183)

*Preconditions*: [s, s + rlen) is a valid range[.](#string.view.ops-2.sentence-1)

[3](#string.view.ops-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1187)

*Effects*: Equivalent to traits​::​copy(s, data() + pos, rlen)[.](#string.view.ops-3.sentence-1)

[4](#string.view.ops-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1191)

*Returns*: rlen[.](#string.view.ops-4.sentence-1)

[5](#string.view.ops-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1195)

*Throws*: out_of_range if pos > size()[.](#string.view.ops-5.sentence-1)

[6](#string.view.ops-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1199)

*Complexity*: O(rlen)[.](#string.view.ops-6.sentence-1)

[ð](#lib:substr,basic_string_view)

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

[7](#string.view.ops-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1212)

Let rlen be the smaller of n and size() - pos[.](#string.view.ops-7.sentence-1)

[8](#string.view.ops-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1215)

*Effects*: Determines rlen, the effective length of the string to reference[.](#string.view.ops-8.sentence-1)

[9](#string.view.ops-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1219)

*Returns*: basic_string_view(data() + pos, rlen)[.](#string.view.ops-9.sentence-1)

[10](#string.view.ops-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1223)

*Throws*: out_of_range if pos > size()[.](#string.view.ops-10.sentence-1)

[ð](#lib:compare,basic_string_view)

`constexpr int compare(basic_string_view str) const noexcept;
`

[11](#string.view.ops-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1234)

Let rlen be the smaller of size() and str.size()[.](#string.view.ops-11.sentence-1)

[12](#string.view.ops-12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1237)

*Effects*: Determines rlen, the effective length of the strings to compare[.](#string.view.ops-12.sentence-1)

The function then compares the two strings by calling traits​::​compare(data(), str.data(), rlen)[.](#string.view.ops-12.sentence-2)

[13](#string.view.ops-13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1242)

*Returns*: The nonzero result if the result of the comparison is nonzero[.](#string.view.ops-13.sentence-1)

Otherwise, returns a value as indicated in Table [88](#tab:string.view.compare "Table 88: compare() results")[.](#string.view.ops-13.sentence-2)

Table [88](#tab:string.view.compare) — compare() results [[tab:string.view.compare]](./tab:string.view.compare)  

| [ð](#tab:string.view.compare-row-1)<br>**Condition** | **Return Value** |
| --- | --- |
| [ð](#tab:string.view.compare-row-2)<br>size() < str.size() | < 0 |
| [ð](#tab:string.view.compare-row-3)<br>size() == str.size() | 0 |
| [ð](#tab:string.view.compare-row-4)<br>size() > str.size() | > 0 |

[14](#string.view.ops-14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1252)

*Complexity*: O(rlen)[.](#string.view.ops-14.sentence-1)

[ð](#lib:compare,basic_string_view_)

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

[15](#string.view.ops-15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1263)

*Effects*: Equivalent to: return substr(pos1, n1).compare(str);

[ð](#lib:compare,basic_string_view__)

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

[16](#string.view.ops-16)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1275)

*Effects*: Equivalent to: return substr(pos1, n1).compare(str.substr(pos2, n2));

[ð](#lib:compare,basic_string_view___)

`constexpr int compare(const charT* s) const;
`

[17](#string.view.ops-17)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1286)

*Effects*: Equivalent to: return compare(basic_string_view(s));

[ð](#lib:compare,basic_string_view____)

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

[18](#string.view.ops-18)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1297)

*Effects*: Equivalent to: return substr(pos1, n1).compare(basic_string_view(s));

[ð](#lib:compare,basic_string_view_____)

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

[19](#string.view.ops-19)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1308)

*Effects*: Equivalent to: return substr(pos1, n1).compare(basic_string_view(s, n2));

[ð](#lib:starts_with,basic_string_view)

`constexpr bool starts_with(basic_string_view x) const noexcept;
`

[20](#string.view.ops-20)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1319)

Let rlen be the smaller of size() and x.size()[.](#string.view.ops-20.sentence-1)

[21](#string.view.ops-21)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1322)

*Effects*: Equivalent to: return basic_string_view(data(), rlen) == x;

[ð](#lib:starts_with,basic_string_view_)

`constexpr bool starts_with(charT x) const noexcept;
`

[22](#string.view.ops-22)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1333)

*Effects*: Equivalent to: return !empty() && traits​::​eq(front(), x);

[ð](#lib:starts_with,basic_string_view__)

`constexpr bool starts_with(const charT* x) const;
`

[23](#string.view.ops-23)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1344)

*Effects*: Equivalent to: return starts_with(basic_string_view(x));

[ð](#lib:ends_with,basic_string_view)

`constexpr bool ends_with(basic_string_view x) const noexcept;
`

[24](#string.view.ops-24)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1355)

Let rlen be the smaller of size() and x.size()[.](#string.view.ops-24.sentence-1)

[25](#string.view.ops-25)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1358)

*Effects*: Equivalent to:return basic_string_view(data() + (size() - rlen), rlen) == x;

[ð](#lib:ends_with,basic_string_view_)

`constexpr bool ends_with(charT x) const noexcept;
`

[26](#string.view.ops-26)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1372)

*Effects*: Equivalent to: return !empty() && traits​::​eq(back(), x);

[ð](#lib:ends_with,basic_string_view__)

`constexpr bool ends_with(const charT* x) const;
`

[27](#string.view.ops-27)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1383)

*Effects*: Equivalent to: return ends_with(basic_string_view(x));

[ð](#lib:contains,basic_string_view)

`constexpr bool contains(basic_string_view x) const noexcept;
constexpr bool contains(charT x) const noexcept;
constexpr bool contains(const charT* x) const;
`

[28](#string.view.ops-28)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1396)

*Effects*: Equivalent to: return find(x) != npos;

#### [27.3.3.9](#string.view.find) Searching [[string.view.find]](string.view.find)

[1](#string.view.find-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1403)

Member functions in this subclause have complexity O(size() * str.size()) at worst,
although implementations should do better[.](#string.view.find-1.sentence-1)

[2](#string.view.find-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1407)

Let *F* be one offind,rfind,find_first_of,find_last_of,find_first_not_of,
andfind_last_not_of[.](#string.view.find-2.sentence-1)

- [(2.1)](#string.view.find-2.1)

Each member function of the formconstexpr *return-type* *F*(const charT* s, size_type pos) const; has effects equivalent to: return *F*(basic_string_view(s), pos);

- [(2.2)](#string.view.find-2.2)

Each member function of the formconstexpr *return-type* *F*(const charT* s, size_type pos, size_type n) const; has effects equivalent to: return *F*(basic_string_view(s, n), pos);

- [(2.3)](#string.view.find-2.3)

Each member function of the formconstexpr *return-type* *F*(charT c, size_type pos) const noexcept; has effects equivalent to: return *F*(basic_string_view(addressof(c), 1), pos);

[ð](#lib:find,basic_string_view)

`constexpr size_type find(basic_string_view str, size_type pos = 0) const noexcept;
`

[3](#string.view.find-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1445)

Let xpos be the lowest position, if possible, such that the following conditions hold:

- [(3.1)](#string.view.find-3.1)

pos <= xpos

- [(3.2)](#string.view.find-3.2)

xpos + str.size() <= size()

- [(3.3)](#string.view.find-3.3)

traits​::​eq(*data_*[xpos + I], str[I]) for all elements I of the string referenced by str[.](#string.view.find-3.sentence-1)

[4](#string.view.find-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1456)

*Effects*: Determines xpos[.](#string.view.find-4.sentence-1)

[5](#string.view.find-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1460)

*Returns*: xpos if the function can determine such a value for xpos[.](#string.view.find-5.sentence-1)

Otherwise, returns npos[.](#string.view.find-5.sentence-2)

[ð](#lib:rfind,basic_string_view)

`constexpr size_type rfind(basic_string_view str, size_type pos = npos) const noexcept;
`

[6](#string.view.find-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1472)

Let xpos be the highest position, if possible, such that the following conditions hold:

- [(6.1)](#string.view.find-6.1)

xpos <= pos

- [(6.2)](#string.view.find-6.2)

xpos + str.size() <= size()

- [(6.3)](#string.view.find-6.3)

traits​::​eq(*data_*[xpos + I], str[I]) for all elements I of the string referenced by str[.](#string.view.find-6.sentence-1)

[7](#string.view.find-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1483)

*Effects*: Determines xpos[.](#string.view.find-7.sentence-1)

[8](#string.view.find-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1487)

*Returns*: xpos if the function can determine such a value for xpos[.](#string.view.find-8.sentence-1)

Otherwise, returns npos[.](#string.view.find-8.sentence-2)

[ð](#lib:find_first_of,basic_string_view)

`constexpr size_type find_first_of(basic_string_view str, size_type pos = 0) const noexcept;
`

[9](#string.view.find-9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1499)

Let xpos be the lowest position, if possible, such that the following conditions hold:

- [(9.1)](#string.view.find-9.1)

pos <= xpos

- [(9.2)](#string.view.find-9.2)

xpos < size()

- [(9.3)](#string.view.find-9.3)

traits​::​eq(*data_*[xpos], str[I]) for some element I of the string referenced by str[.](#string.view.find-9.sentence-1)

[10](#string.view.find-10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1510)

*Effects*: Determines xpos[.](#string.view.find-10.sentence-1)

[11](#string.view.find-11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1514)

*Returns*: xpos if the function can determine such a value for xpos[.](#string.view.find-11.sentence-1)

Otherwise, returns npos[.](#string.view.find-11.sentence-2)

[ð](#lib:find_last_of,basic_string_view)

`constexpr size_type find_last_of(basic_string_view str, size_type pos = npos) const noexcept;
`

[12](#string.view.find-12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1526)

Let xpos be the highest position, if possible, such that the following conditions hold:

- [(12.1)](#string.view.find-12.1)

xpos <= pos

- [(12.2)](#string.view.find-12.2)

xpos < size()

- [(12.3)](#string.view.find-12.3)

traits​::​eq(*data_*[xpos], str[I]) for some element I of the string referenced by str[.](#string.view.find-12.sentence-1)

[13](#string.view.find-13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1537)

*Effects*: Determines xpos[.](#string.view.find-13.sentence-1)

[14](#string.view.find-14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1541)

*Returns*: xpos if the function can determine such a value for xpos[.](#string.view.find-14.sentence-1)

Otherwise, returns npos[.](#string.view.find-14.sentence-2)

[ð](#lib:find_first_not_of,basic_string_view)

`constexpr size_type find_first_not_of(basic_string_view str, size_type pos = 0) const noexcept;
`

[15](#string.view.find-15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1553)

Let xpos be the lowest position, if possible, such that the following conditions hold:

- [(15.1)](#string.view.find-15.1)

pos <= xpos

- [(15.2)](#string.view.find-15.2)

xpos < size()

- [(15.3)](#string.view.find-15.3)

traits​::​eq(*data_*[xpos], str[I]) for no element I of the string referenced by str[.](#string.view.find-15.sentence-1)

[16](#string.view.find-16)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1564)

*Effects*: Determines xpos[.](#string.view.find-16.sentence-1)

[17](#string.view.find-17)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1568)

*Returns*: xpos if the function can determine such a value for xpos[.](#string.view.find-17.sentence-1)

Otherwise, returns npos[.](#string.view.find-17.sentence-2)

[ð](#lib:find_last_not_of,basic_string_view)

`constexpr size_type find_last_not_of(basic_string_view str, size_type pos = npos) const noexcept;
`

[18](#string.view.find-18)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1579)

Let xpos be the highest position, if possible, such that the following conditions hold:

- [(18.1)](#string.view.find-18.1)

xpos <= pos

- [(18.2)](#string.view.find-18.2)

xpos < size()

- [(18.3)](#string.view.find-18.3)

traits​::​eq(*data_*[xpos], str[I]) for no element I of the string referenced by str[.](#string.view.find-18.sentence-1)

[19](#string.view.find-19)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1590)

*Effects*: Determines xpos[.](#string.view.find-19.sentence-1)

[20](#string.view.find-20)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L1594)

*Returns*: xpos if the function can determine such a value for xpos[.](#string.view.find-20.sentence-1)

Otherwise, returns npos[.](#string.view.find-20.sentence-2)
