Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/string/basic string view"

From cppreference.com
< cpp‎ | string
(Specify that a mismatch of Traits::char_type and CharT leads to UB)
m
Line 70: Line 70:
 
{{dsc inc | cpp/string/basic_string_view/dsc empty}}
 
{{dsc inc | cpp/string/basic_string_view/dsc empty}}
  
{{dsc h2 | Modifers}}
+
{{dsc h2 | Modifiers}}
 
{{dsc inc | cpp/string/basic_string_view/dsc remove_prefix}}
 
{{dsc inc | cpp/string/basic_string_view/dsc remove_prefix}}
 
{{dsc inc | cpp/string/basic_string_view/dsc remove_suffix}}
 
{{dsc inc | cpp/string/basic_string_view/dsc remove_suffix}}

Revision as of 12:49, 3 October 2017

 
 
 
 
Defined in header <string_view>
template<

    class CharT,
    class Traits = std::char_traits<CharT>

> class basic_string_view;
(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

Template parameters

CharT - character type
Traits - Template:concept class specifying the operations on the character type. Like for basic_string, Traits::char_type must name the same type as CharT or the behavior is undefined.

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 constant Template:concept and Template:concept whose value_type is CharT
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.

Member functions

constructs a basic_string_view
(public member function) [edit]
assigns a view
(public member function) [edit]
Iterators
returns an iterator to the beginning
(public member function) [edit]
returns an iterator to the end
(public member function) [edit]
returns a reverse iterator to the beginning
(public member function) [edit]
returns a reverse iterator to the end
(public member function) [edit]
Element access
accesses the specified character
(public member function) [edit]
accesses the specified character with bounds checking
(public member function) [edit]
accesses the first character
(public member function) [edit]
accesses the last character
(public member function) [edit]
returns a pointer to the first character of a view
(public member function) [edit]
Capacity
returns the number of characters
(public member function) [edit]
returns the maximum number of characters
(public member function) [edit]
checks whether the view is empty
(public member function) [edit]
Modifiers
shrinks the view by moving its start forward
(public member function) [edit]
shrinks the view by moving its end backward
(public member function) [edit]
swaps the contents
(public member function) [edit]
Operations
copies characters
(public member function) [edit]
returns a substring
(public member function) [edit]
compares two views
(public member function) [edit]
find characters in the view
(public member function) [edit]
find the last occurrence of a substring
(public member function) [edit]
find first occurrence of characters
(public member function) [edit]
find last occurrence of characters
(public member function) [edit]
find first absence of characters
(public member function) [edit]
find last absence of characters
(public member function) [edit]

Constants

[static]
special value. The exact meaning depends on the context
(public static member constant) [edit]

Non-member functions

(C++17)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
lexicographically compares two string views
(function template) [edit]
Input/output
performs stream output on string views
(function template) [edit]

Literals

Defined in inline namespace std::literals::string_view_literals
creates a string view of a character array literal
(function) [edit]

Helper classes

hash support for string views
(class template specialization) [edit]