std::basic_string_view
From cppreference.com
| Defined in header <string_view>
|
||
| template< class CharT, |
(since C++17) | |
The class template basic_string_view describes an object that can refer to a constant contiguous sequence of char-like objects with the first element of the sequence at position zero.
A typical implementation holds only two members: a pointer to constant CharT and a size.
Several typedefs for common character types are provided:
| Defined in header
<string_view> | |
| Type | Definition |
| std::string_view | std::basic_string_view<char> |
| std::wstring_view | std::basic_string_view<wchar_t> |
| std::u16string_view | std::basic_string_view<char16_t> |
| std::u32string_view | std::basic_string_view<char32_t> |
Contents |
[edit] Template parameters
| CharT | - | character type |
| Traits | - | CharTraits class specifying the operations on the character type. Traits::char_type must name the same type as CharT.
|
[edit] Member types
| Member type | Definition |
traits_type
|
Traits
|
value_type
|
CharT
|
pointer
|
CharT*
|
const_pointer
|
const CharT*
|
reference
|
CharT&
|
const_reference
|
const CharT&
|
const_iterator
|
implementation-defined RandomAccessIterator
|
iterator
|
const_iterator
|
reverse_iterator
|
const_reverse_iterator
|
const_reverse_iterator
|
std::reverse_iterator<const_iterator> |
size_type
|
std::size_t |
difference_type
|
std::ptrdiff_t |
Note: iterator and const_iterator are the same type because string views are views into constant character sequences.
[edit] Member functions
constructs a basic_string_view (public member function) | |
| assigns a view (public member function) | |
Iterators | |
| returns an iterator to the beginning (public member function) | |
| returns an iterator to the end (public member function) | |
| returns a reverse iterator to the beginning (public member function) | |
| returns a reverse iterator to the end (public member function) | |
Element access | |
| access specified character (public member function) | |
| access specified character with bounds checking (public member function) | |
| accesses the first character (public member function) | |
| accesses the last character (public member function) | |
| returns a pointer to the first character of a view (public member function) | |
Capacity | |
| returns the number of characters (public member function) | |
| returns the maximum number of characters (public member function) | |
| checks whether the view is empty (public member function) | |
Modifers | |
| shrinks the view by moving its start forward (public member function) | |
| shrinks the view by moving its end backward (public member function) | |
| swaps the contents (public member function) | |
Operations | |
| copies characters (public member function) | |
| returns a substring (public member function) | |
| compares two views (public member function) | |
| find characters in the view (public member function) | |
| find the last occurrence of a substring (public member function) | |
| find first occurrence of characters (public member function) | |
| find last occurrence of characters (public member function) | |
| find first absence of characters (public member function) | |
| find last absence of characters (public member function) | |
Constants | |
| [static] |
special value. The exact meaning depends on the context (public static member constant) |
[edit] Non-member functions
| lexicographically compares two string views (function template) | |
Input/output | |
| performs stream output on string views (function template) | |
[edit] Literals
| Defined in inline namespace
std::literals::string_view_literals | |
| (C++17) |
Creates a string view of a character array literal (function) |
[edit] Helper classes
| hash support for string views (class template specialization) |