[string.view]

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

## 27.3 String view classes [string.view]

### [27.3.1](#general) General [[string.view.general]](string.view.general)

[1](#general-1)

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

The class template basic_string_view describes an object that can refer to a constant contiguous sequence of char-like ([[strings.general]](strings.general "27.1 General")) objects with the first element of the sequence at position zero[.](#general-1.sentence-1)

In the rest of [string.view], the type of the char-like objects held in a basic_string_view object is designated by charT[.](#general-1.sentence-2)

[2](#general-2)

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

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

The library provides implicit conversions from const charT* and std​::​basic_string<charT, ...> to std​::​basic_string_view<charT, ...> so that user code can accept just std​::​basic_string_view<charT> as a non-templated parameter wherever a sequence of characters is expected[.](#general-2.sentence-1)

User-defined types can define their own implicit conversions to std​::​basic_string_view<charT> in order to interoperate with these functions[.](#general-2.sentence-2)

â *end note*]

### [27.3.2](#synop) Header <string_view> synopsis [[string.view.synop]](string.view.synop)

[ð](#header:%3cstring_view%3e)

// mostly freestanding#include <compare> // see [[compare.syn]](compare.syn "17.12.1 Header <compare> synopsis")namespace std {// [[string.view.template]](#template "27.3.3 Class template basic_­string_­view"), class template basic_string_viewtemplate<class charT, class traits = char_traits<charT>>class basic_string_view; // partially freestandingtemplate<class charT, class traits>constexpr bool ranges::enable_view<basic_string_view<charT, traits>> = true; template<class charT, class traits>constexpr bool ranges::enable_borrowed_range<basic_string_view<charT, traits>> = true; // [[string.view.comparison]](#comparison "27.3.4 Non-member comparison functions"), non-member comparison functionstemplate<class charT, class traits>constexpr bool operator==(basic_string_view<charT, traits> x,
 type_identity_t<basic_string_view<charT, traits>> y) noexcept; template<class charT, class traits>constexpr *see below* operator<=>(basic_string_view<charT, traits> x,
 type_identity_t<basic_string_view<charT,
 traits>> y) noexcept; // [[string.view.io]](#io "27.3.5 Inserters and extractors"), inserters and extractorstemplate<class charT, class traits> basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os,
 basic_string_view<charT, traits> str); // hosted// basic_string_view [*typedef-name*](dcl.typedef#nt:typedef-name "9.2.4 The typedef specifier [dcl.typedef]")*s*using string_view = basic_string_view<char>; using u8string_view = basic_string_view<char8_t>; using u16string_view = basic_string_view<char16_t>; using u32string_view = basic_string_view<char32_t>; using wstring_view = basic_string_view<wchar_t>; // [[string.view.hash]](#hash "27.3.6 Hash support"), hash supporttemplate<class T> struct hash; template<> struct hash<string_view>; template<> struct hash<u8string_view>; template<> struct hash<u16string_view>; template<> struct hash<u32string_view>; template<> struct hash<wstring_view>; inline namespace literals {inline namespace string_view_literals {// [[string.view.literals]](#literals "27.3.7 Suffix for basic_­string_­view literals"), suffix for basic_string_view literalsconstexpr string_view operator""sv(const char* str, size_t len) noexcept; constexpr u8string_view operator""sv(const char8_t* str, size_t len) noexcept; constexpr u16string_view operator""sv(const char16_t* str, size_t len) noexcept; constexpr u32string_view operator""sv(const char32_t* str, size_t len) noexcept; constexpr wstring_view operator""sv(const wchar_t* str, size_t len) noexcept; }}}

[1](#synop-1)

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

The function templates defined in [[utility.swap]](utility.swap "22.2.2 swap") and [[iterator.range]](iterator.range "24.7 Range access") are available when <string_view> is included[.](#synop-1.sentence-1)

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

#### [27.3.3.1](#template.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]](#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]](#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]](#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]](#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]](#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]](#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]](#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]](#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]](#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](#template.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"))[.](#template.general-1.sentence-1)

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

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

â *end note*]

[2](#template.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[.](#template.general-2.sentence-1)

[3](#template.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[.](#template.general-3.sentence-1)

[4](#template.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"))[.](#template.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](#cons) Construction and assignment [[string.view.cons]](string.view.cons)

[ð](#lib:basic_string_view,constructor)

`constexpr basic_string_view() noexcept;
`

[1](#cons-1)

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

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

[ð](#lib:basic_string_view,constructor_)

`constexpr basic_string_view(const charT* str);
`

[2](#cons-2)

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

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

[3](#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)[.](#cons-3.sentence-1)

[4](#cons-4)

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

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

[ð](#lib:basic_string_view,constructor__)

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

[5](#cons-5)

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

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

[6](#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[.](#cons-6.sentence-1)

[ð](#lib:basic_string_view,constructor___)

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

[7](#cons-7)

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

*Constraints*: 

- [(7.1)](#cons-7.1)

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

- [(7.2)](#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>[.](#cons-7.2.sentence-1)

- [(7.3)](#cons-7.3)

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

- [(7.4)](#cons-7.4)

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

[8](#cons-8)

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

*Preconditions*: 

- [(8.1)](#cons-8.1)

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

- [(8.2)](#cons-8.2)

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

- [(8.3)](#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>[.](#cons-8.3.sentence-1)

[9](#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[.](#cons-9.sentence-1)

[10](#cons-10)

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

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

[ð](#lib:basic_string_view,constructor____)

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

[11](#cons-11)

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

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

[12](#cons-12)

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

*Constraints*: 

- [(12.1)](#cons-12.1)

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

- [(12.2)](#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)](#cons-12.3)

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

- [(12.4)](#cons-12.4)

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

- [(12.5)](#cons-12.5)

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

[13](#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)[.](#cons-13.sentence-1)

[14](#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)[.](#cons-14.sentence-1)

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

[ð](#deduct-itemdecl:1)

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

[1](#deduct-1)

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

*Constraints*: 

- [(1.1)](#deduct-1.1)

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

- [(1.2)](#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>[.](#deduct-1.2.sentence-1)

[ð](#deduct-itemdecl:2)

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

[2](#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]")[.](#deduct-2.sentence-1)

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

[ð](#lib:const_iterator,basic_string_view_)

`using const_iterator = implementation-defined;
`

[1](#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[.](#iterators-1.sentence-1)

[2](#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[.](#iterators-2.sentence-1)

[ð](#lib:begin,basic_string_view)

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

[3](#iterators-3)

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

*Returns*: An iterator such that

- [(3.1)](#iterators-3.1)

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

- [(3.2)](#iterators-3.2)

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

[ð](#lib:end,basic_string_view)

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

[4](#iterators-4)

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

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

[ð](#lib:rbegin,basic_string_view)

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

[5](#iterators-5)

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

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

[ð](#lib:rend,basic_string_view)

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

[6](#iterators-6)

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

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

#### [27.3.3.5](#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](#capacity-1)

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

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

[ð](#lib:max_size,basic_string_view)

`constexpr size_type max_size() const noexcept;
`

[2](#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[.](#capacity-2.sentence-1)

[ð](#lib:empty,basic_string_view)

`constexpr bool empty() const noexcept;
`

[3](#capacity-3)

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

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

#### [27.3.3.6](#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](#access-1)

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

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

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

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

â *end note*]

[2](#access-2)

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

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

[3](#access-3)

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

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

[ð](#lib:at,basic_string_view)

`constexpr const_reference at(size_type pos) const;
`

[4](#access-4)

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

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

[5](#access-5)

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

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

[ð](#lib:front,basic_string_view)

`constexpr const_reference front() const;
`

[6](#access-6)

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

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

[7](#access-7)

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

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

[8](#access-8)

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

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

[ð](#lib:back,basic_string_view)

`constexpr const_reference back() const;
`

[9](#access-9)

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

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

[10](#access-10)

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

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

[11](#access-11)

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

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

[ð](#lib:data,basic_string_view)

`constexpr const_pointer data() const noexcept;
`

[12](#access-12)

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

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

[13](#access-13)

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

[*Note [2](#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[.](#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[.](#access-13.sentence-2)

â *end note*]

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

[ð](#lib:remove_prefix,basic_string_view)

`constexpr void remove_prefix(size_type n);
`

[1](#modifiers-1)

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

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

[2](#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](#modifiers-3)

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

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

[4](#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](#modifiers-5)

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

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

#### [27.3.3.8](#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](#ops-1)

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

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

[2](#ops-2)

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

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

[3](#ops-3)

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

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

[4](#ops-4)

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

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

[5](#ops-5)

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

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

[6](#ops-6)

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

*Complexity*: O(rlen)[.](#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](#ops-7)

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

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

[8](#ops-8)

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

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

[9](#ops-9)

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

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

[10](#ops-10)

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

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

[ð](#lib:compare,basic_string_view)

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

[11](#ops-11)

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

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

[12](#ops-12)

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

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

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

[13](#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[.](#ops-13.sentence-1)

Otherwise, returns a value as indicated in Table [88](#tab:string.view.compare "Table 88: compare() results")[.](#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](#ops-14)

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

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

[ð](#lib:compare,basic_string_view_)

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

[15](#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](#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](#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](#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](#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](#ops-20)

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

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

[21](#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](#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](#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](#ops-24)

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

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

[25](#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](#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](#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](#ops-28)

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

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

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

[1](#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[.](#find-1.sentence-1)

[2](#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[.](#find-2.sentence-1)

- [(2.1)](#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)](#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)](#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](#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)](#find-3.1)

pos <= xpos

- [(3.2)](#find-3.2)

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

- [(3.3)](#find-3.3)

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

[4](#find-4)

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

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

[5](#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[.](#find-5.sentence-1)

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

[ð](#lib:rfind,basic_string_view)

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

[6](#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)](#find-6.1)

xpos <= pos

- [(6.2)](#find-6.2)

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

- [(6.3)](#find-6.3)

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

[7](#find-7)

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

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

[8](#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[.](#find-8.sentence-1)

Otherwise, returns npos[.](#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](#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)](#find-9.1)

pos <= xpos

- [(9.2)](#find-9.2)

xpos < size()

- [(9.3)](#find-9.3)

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

[10](#find-10)

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

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

[11](#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[.](#find-11.sentence-1)

Otherwise, returns npos[.](#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](#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)](#find-12.1)

xpos <= pos

- [(12.2)](#find-12.2)

xpos < size()

- [(12.3)](#find-12.3)

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

[13](#find-13)

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

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

[14](#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[.](#find-14.sentence-1)

Otherwise, returns npos[.](#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](#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)](#find-15.1)

pos <= xpos

- [(15.2)](#find-15.2)

xpos < size()

- [(15.3)](#find-15.3)

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

[16](#find-16)

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

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

[17](#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[.](#find-17.sentence-1)

Otherwise, returns npos[.](#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](#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)](#find-18.1)

xpos <= pos

- [(18.2)](#find-18.2)

xpos < size()

- [(18.3)](#find-18.3)

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

[19](#find-19)

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

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

[20](#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[.](#find-20.sentence-1)

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

### [27.3.4](#comparison) Non-member comparison functions [[string.view.comparison]](string.view.comparison)

[ð](#lib:operator==,basic_string_view)

`template<class charT, class traits>
  constexpr bool operator==(basic_string_view<charT, traits> lhs,
                            type_identity_t<basic_string_view<charT, traits>> rhs) noexcept;
`

[1](#comparison-1)

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

*Returns*: lhs.compare(rhs) == 0[.](#comparison-1.sentence-1)

[ð](#lib:operator%3c=%3e,basic_string_view)

`template<class charT, class traits>
  constexpr see below operator<=>(basic_string_view<charT, traits> lhs,
                                  type_identity_t<basic_string_view<charT, traits>> rhs) noexcept;
`

[2](#comparison-2)

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

Let R denote the type traits​::​comparison_category if
that [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3 Qualified names [expr.prim.id.qual]") is valid and denotes a type ([[temp.deduct]](temp.deduct "13.10.3 Template argument deduction")),
otherwise R is weak_ordering[.](#comparison-2.sentence-1)

[3](#comparison-3)

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

*Mandates*: R denotes a comparison category type ([[cmp.categories]](cmp.categories "17.12.2 Comparison category types"))[.](#comparison-3.sentence-1)

[4](#comparison-4)

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

*Returns*: static_cast<R>(lhs.compare(rhs) <=> 0)[.](#comparison-4.sentence-1)

[5](#comparison-5)

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

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

The usage of type_identity_t as parameter
ensures that an object of type basic_string_view<charT, traits> can always be compared with an object of a type T with
an implicit conversion to basic_string_view<charT, traits>, and
vice versa, as per [[over.match.oper]](over.match.oper "12.2.2.3 Operators in expressions")[.](#comparison-5.sentence-1)

â *end note*]

### [27.3.5](#io) Inserters and extractors [[string.view.io]](string.view.io)

[ð](#lib:operator%3c%3c,basic_string_view)

`template<class charT, class traits>
  basic_ostream<charT, traits>&
    operator<<(basic_ostream<charT, traits>& os, basic_string_view<charT, traits> str);
`

[1](#io-1)

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

*Effects*: Behaves as a formatted output
function ([[ostream.formatted.reqmts]](ostream.formatted.reqmts "31.7.6.3.1 Common requirements")) of os[.](#io-1.sentence-1)

Forms a character sequenceseq, initially consisting of the elements defined by the range
[str.begin(), str.end())[.](#io-1.sentence-2)

Determines padding for seq as described in [[ostream.formatted.reqmts]](ostream.formatted.reqmts "31.7.6.3.1 Common requirements")[.](#io-1.sentence-3)

Then inserts seq as if by callingos.rdbuf()->sputn(​seq, n), where n is the larger
of os.width() and str.size();
then calls os.​width(0)[.](#io-1.sentence-4)

[2](#io-2)

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

*Returns*: os[.](#io-2.sentence-1)

### [27.3.6](#hash) Hash support [[string.view.hash]](string.view.hash)

[ð](#lib:hash,string_view)

`template<> struct hash<string_view>;
template<> struct hash<u8string_view>;
template<> struct hash<u16string_view>;
template<> struct hash<u32string_view>;
template<> struct hash<wstring_view>;
`

[1](#hash-1)

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

The specialization is enabled ([[unord.hash]](unord.hash "22.10.19 Class template hash"))[.](#hash-1.sentence-1)

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

The hash value of a string view object is equal to the hash value of
the corresponding string object ([[basic.string.hash]](basic.string.hash "27.4.6 Hash support"))[.](#hash-1.sentence-2)

â *end note*]

### [27.3.7](#literals) Suffix for basic_string_view literals [[string.view.literals]](string.view.literals)

[ð](#lib:operator%22%22sv,string_view)

`constexpr string_view operator""sv(const char* str, size_t len) noexcept;
`

[1](#literals-1)

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

*Returns*: string_view{str, len}[.](#literals-1.sentence-1)

[ð](#lib:operator%22%22sv,u8string_view)

`constexpr u8string_view operator""sv(const char8_t* str, size_t len) noexcept;
`

[2](#literals-2)

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

*Returns*: u8string_view{str, len}[.](#literals-2.sentence-1)

[ð](#lib:operator%22%22sv,u16string_view)

`constexpr u16string_view operator""sv(const char16_t* str, size_t len) noexcept;
`

[3](#literals-3)

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

*Returns*: u16string_view{str, len}[.](#literals-3.sentence-1)

[ð](#lib:operator%22%22sv,u32string_view)

`constexpr u32string_view operator""sv(const char32_t* str, size_t len) noexcept;
`

[4](#literals-4)

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

*Returns*: u32string_view{str, len}[.](#literals-4.sentence-1)

[ð](#lib:operator%22%22sv,wstring_view)

`constexpr wstring_view operator""sv(const wchar_t* str, size_t len) noexcept;
`

[5](#literals-5)

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

*Returns*: wstring_view{str, len}[.](#literals-5.sentence-1)
