GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing eel.is — [string.view] 27 Strings library [strings]27.3 String view classes [string.view]27.3.1 General [string.view.general]27.3.2 Header <string_view> synopsis [string.view.synop]27.3.3 Class template basic_string_view [string.view.template]27.3.3.1 General [string.view.template.general]27.3.3.2 Construction and assignment [string.view.cons]27.3.3.3 Deduction guides [string.view.deduct]27.3.3.4 Iterator support [string.view.iterators]27.3.3.5 Capacity [string.view.capacity]27.3.3.6 Element access [string.view.access]27.3.3.7 Modifiers [string.view.modifiers]27.3.3.8 String operations [string.view.ops]27.3.3.9 Searching [string.view.find]27.3.4 Non-member comparison functions [string.view.comparison]27.3.5 Inserters and extractors [string.view.io]27.3.6 Hash support [string.view.hash]27.3.7 Suffix for basic_string_view literals [string.view.literals]27.3.1 General [string.view.general]The class template basic_string_view describes an object
that can refer to a constant contiguous sequence of char-like ([strings.general]) objects
with the first element of the sequence at position zero. In the rest of [string.view], the type of the char-like objects
held in a basic_string_view object is designated by charT. [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. User-defined types can define their own implicit conversions
to std::basic_string_view<charT> in order to interoperate with these functions. — end note]27.3.2 Header <string_view> synopsis [string.view.synop]// mostly freestanding
#include <compare> // see [compare.syn]
namespace std {
// [string.view.template], class template basic_string_view
template<class charT, class traits = char_traits<charT>>
class basic_string_view; // partially freestanding
template<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], non-member comparison functions
template<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], inserters and extractors
template<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-names
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 support
template<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], suffix for basic_string_view literals
constexpr 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;
}
}
}
The function templates defined in [utility.swap] and [iterator.range]
are available when <string_view> is included. 27.3.3 Class template basic_string_view [string.view.template]namespace std {
template<class charT, class traits = char_traits<charT>>
class basic_string_view {
public:
// types
using traits_type = traits;
using value_type = charT;
using pointer = value_type*;
using const_pointer = const value_type*;
using reference = value_type&;
using const_reference = const value_type&;
using const_iterator = implementation-defined; // see [string.view.iterators]
using iterator = const_iterator;¹⁹⁰
using const_reverse_iterator = reverse_iterator<const_iterator>;
using reverse_iterator = const_reverse_iterator;
using size_type = size_t;
using difference_type = ptrdiff_t;
static constexpr size_type npos = size_type(-1);
// [string.view.cons], construction and assignment
constexpr basic_string_view() noexcept;
constexpr basic_string_view(const basic_string_view&) noexcept = default;
constexpr basic_string_view& operator=(const basic_string_view&) noexcept = default;
constexpr basic_string_view(const charT* str);
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], iterator support
constexpr const_iterator begin() const noexcept;
constexpr const_iterator end() const noexcept;
constexpr const_iterator cbegin() const noexcept;
constexpr const_iterator cend() const noexcept;
constexpr const_reverse_iterator rbegin() const noexcept;
constexpr const_reverse_iterator rend() const noexcept;
constexpr const_reverse_iterator crbegin() const noexcept;
constexpr const_reverse_iterator crend() const noexcept;
// [string.view.capacity], capacity
constexpr size_type size() const noexcept;
constexpr size_type length() const noexcept;
constexpr size_type max_size() const noexcept;
constexpr bool empty() const noexcept;
// [string.view.access], element access
constexpr const_reference operator[](size_type pos) const;
constexpr const_reference at(size_type pos) const; // freestanding-deleted
constexpr const_reference front() const;
constexpr const_reference back() const;
constexpr const charT* data() const noexcept;
// [string.view.modifiers], modifiers
constexpr void remove_prefix(size_type n);
constexpr void remove_suffix(size_type n);
constexpr void swap(basic_string_view& s) noexcept;
// [string.view.ops], string operations
constexpr size_type copy(charT* s, size_type n,
size_type pos = 0) const; // freestanding-deleted
constexpr basic_string_view substr(size_type pos = 0,
size_type n = npos) const; // freestanding-deleted
constexpr basic_string_view subview(size_type pos = 0,
size_type n = npos) const; // freestanding-deleted
constexpr int compare(basic_string_view s) const noexcept;
constexpr int compare(size_type pos1, size_type n1,
basic_string_view s) const; // freestanding-deleted
constexpr int compare(size_type pos1, size_type n1, basic_string_view s,
size_type pos2, size_type n2) const; // freestanding-deleted
constexpr int compare(const charT* s) const;
constexpr int compare(size_type pos1, size_type n1,
const charT* s) const; // freestanding-deleted
constexpr int compare(size_type pos1, size_type n1, const charT* s,
size_type n2) const; // freestanding-deleted
constexpr 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], searching
constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept;
constexpr size_type find(charT c, size_type pos = 0) const noexcept;
constexpr size_type find(const charT* s, size_type pos, size_type n) const;
constexpr size_type find(const charT* s, size_type pos = 0) const;
constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept;
constexpr size_type rfind(charT c, size_type pos = npos) const noexcept;
constexpr size_type rfind(const charT* s, size_type pos, size_type n) const;
constexpr size_type rfind(const charT* s, size_type pos = npos) const;
constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept;
constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept;
constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const;
constexpr size_type find_first_of(const charT* s, size_type pos = 0) const;
constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept;
constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept;
constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const;
constexpr size_type find_last_of(const charT* s, size_type pos = npos) const;
constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept;
constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept;
constexpr size_type find_first_not_of(const charT* s, size_type pos,
size_type n) const;
constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const;
constexpr size_type find_last_not_of(basic_string_view s,
size_type pos = npos) const noexcept;
constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept;
constexpr size_type find_last_not_of(const charT* s, size_type pos,
size_type n) const;
constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const;
private:
const charT* data_; // exposition only
size_type size_; // exposition only
};
// [string.view.deduct], deduction guides
template<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>>;
}
In every specialization basic_string_view<charT, traits>, the type traits shall meet the character traits requirements ([char.traits]). 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. 27.3.3.2 Construction and assignment [string.view.cons]constexpr basic_string_view() noexcept;
constexpr basic_string_view(const charT* str);
constexpr basic_string_view(const charT* str, size_type len);
template<class It, class End>
constexpr basic_string_view(It begin, End end);
Preconditions:
template<class R>
constexpr explicit basic_string_view(R&& r);
Constraints:
27.3.3.3 Deduction guides [string.view.deduct]template<class It, class End>
basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>;
Constraints: template<class R>
basic_string_view(R&&) -> basic_string_view<ranges::range_value_t<R>>;
27.3.3.4 Iterator support [string.view.iterators]using const_iterator = implementation-defined;
A type that meets the requirements
of a constant
Cpp17RandomAccessIterator ([random.access.iterators]),
models contiguous_iterator ([iterator.concept.contiguous]), and
meets the constexpr iterator requirements ([iterator.requirements.general]),
whose value_type is the template parameter charT. All requirements on container iterators ([container.requirements])
apply to basic_string_view::const_iterator as well. constexpr const_iterator begin() const noexcept;
constexpr const_iterator cbegin() const noexcept;
constexpr const_iterator end() const noexcept;
constexpr const_iterator cend() const noexcept;
constexpr const_reverse_iterator rbegin() const noexcept;
constexpr const_reverse_iterator crbegin() const noexcept;
constexpr const_reverse_iterator rend() const noexcept;
constexpr const_reverse_iterator crend() const noexcept;
27.3.3.5 Capacity [string.view.capacity]constexpr size_type size() const noexcept;
constexpr size_type length() const noexcept;
constexpr size_type max_size() const noexcept;
constexpr bool empty() const noexcept;
27.3.3.6 Element access [string.view.access]constexpr const_reference operator[](size_type pos) const;
constexpr const_reference at(size_type pos) const;
constexpr const_reference front() const;
constexpr const_reference back() const;
constexpr const charT* data() const noexcept;
[Note 2: Unlike basic_string::data() and string-literals,
data() can return a pointer to a buffer that is not null-terminated. Therefore it is typically a mistake to pass data() to a function
that takes just a const charT* and expects a null-terminated string. — end note]27.3.3.7 Modifiers [string.view.modifiers]constexpr void remove_prefix(size_type n);
constexpr void remove_suffix(size_type n);
constexpr void swap(basic_string_view& s) noexcept;
27.3.3.8 String operations [string.view.ops]constexpr size_type copy(charT* s, size_type n, size_type pos = 0) const;
constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
constexpr basic_string_view subview(size_type pos = 0, size_type n = npos) const;
constexpr int compare(basic_string_view str) const noexcept;
constexpr int compare(size_type pos1, size_type n1, basic_string_view str) const;
constexpr int compare(size_type pos1, size_type n1, basic_string_view str,
size_type pos2, size_type n2) const;
constexpr int compare(const charT* s) const;
constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
constexpr int compare(size_type pos1, size_type n1, const charT* s, size_type n2) const;
constexpr 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;
27.3.3.9 Searching [string.view.find]Member functions in this subclause have complexity O(size() * str.size()) at worst,
although implementations should do better.
constexpr size_type find(basic_string_view str, size_type pos = 0) const noexcept;
constexpr size_type rfind(basic_string_view str, size_type pos = npos) const noexcept;
constexpr size_type find_first_of(basic_string_view str, size_type pos = 0) const noexcept;
constexpr size_type find_last_of(basic_string_view str, size_type pos = npos) const noexcept;
constexpr size_type find_first_not_of(basic_string_view str, size_type pos = 0) const noexcept;
constexpr size_type find_last_not_of(basic_string_view str, size_type pos = npos) const noexcept;
27.3.4 Non-member comparison functions [string.view.comparison]template<class charT, class traits>
constexpr bool operator==(basic_string_view<charT, traits> lhs,
type_identity_t<basic_string_view<charT, traits>> rhs) noexcept;
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;
Let R denote the type traits::comparison_category if
that qualified-id is valid and denotes a type ([temp.deduct]),
otherwise R is weak_ordering. [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]. — end note]27.3.5 Inserters and extractors [string.view.io]template<class charT, class traits>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os, basic_string_view<charT, traits> str);
27.3.6 Hash support [string.view.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>;
The specialization is enabled ([unord.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]). — end note]27.3.7 Suffix for basic_string_view literals [string.view.literals]constexpr 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;
|
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |