carb::cpp::basic_string_view
Defined in carb/cpp/StringView.h
-
template<class CharT, class Traits = std::char_traits<CharT>>
class basic_string_view The class template basic_string_view describes an object that can refer to a constant contiguous sequence of elements with the first element of the sequence at position zero.
This implementation of
string_view
is a guaranteed ABI- and interop-safe type.- Template Parameters
CharT – character type
Traits – A traits class specifying the operations on the character type. Like for
std::basic_string
,Traits::char_type
must name the same type asCharT
or the program is ill-formed.
Subclassed by omni::structuredlog::BasicStringView< CharT, Traits >
Public Types
-
using const_iterator = omni::detail::PointerIterator<const_pointer, basic_string_view>
implementation defined constant LegacyRandomAccessIterator and LegacyContiguousIterator whose value_type is CharT.
-
using iterator = const_iterator
const_iterator
Note
iterator
andconst_iterator
are the same type because string views are views into constant character sequences.
-
using const_reverse_iterator = std::reverse_iterator<const_iterator>
std::reverse_iterator<const_iterator>
-
using reverse_iterator = const_reverse_iterator
const_reverse_iterator
Public Functions
-
constexpr basic_string_view() noexcept = default
Constructs a basic_string_view.
Constructs an empty basic_string_view. After construction, data() is equal to
nullptr
and size() is equal to0
.
-
constexpr basic_string_view(const basic_string_view &other) noexcept = default
Constructs a basic_string_view.
Constructs a view of the same content as
other
. After construction, data() is equal toother.data()
and size() is equal toother.size()
.- Parameters
other – The string view to copy.
-
inline constexpr basic_string_view(const CharT *s, size_type count)
Constructs a basic_string_view.
Constructs a view of the first count characters of the character array starting with the element pointed by
s
.s
can contain null characters. The behavior is undefined if[s, s + count)
is not a valid range (even though the constructor may not access any of the elements of this range). After construction, data() is equal tos
, and size() is equal tocount
.- Parameters
s – The character array to view.
count – The number of characters in
s
to view.
-
inline constexpr basic_string_view(const CharT *s)
Constructs a basic_string_view.
Constructs a view of the null-terminated character string pointed to by
s
, not including the terminating null character. The length of the view is determined as if byTraits::length(s)
. The behavior is undefined if[s, s + Traits::length(s))
is not a valid range. After construction, data() is equal tos
, and size() is equal toTraits::length(s)
.Note
As a Carbonite extension, this constructor will not participate in overload resolution if
s
is a literalCharT
array. Instead, see basic_string_view(const CharT(&literal)[N]).- Parameters
s – The null-terminated character string to view.
-
template<size_t N>
inline constexpr basic_string_view(const CharT (&literal)[N]) noexcept Constructs a basic_string_view.
Constructs a view of the literal string
literal
, not including the terminating null character. The length of the view is determined byN - 1
as literal strings will have a terminating null character. After construction, data() is equal toliteral
, and size() is equal toN - 1
.Note
This constructor is a Carbonite extension and provided as an optimization. For
std::basic_string_view
, the basic_string_view(const CharT*) constructor would be invoked instead. This allows string views to be constructed as a constant expression from string literals without using the_sv
literal extension.- Parameters
literal – A string literal to view.
-
template<class It>
inline constexpr basic_string_view(It first, It last) Constructs a basic_string_view.
Constructs a basic_string_view over the range
[first, last)
. The behavior is undefined if[first, last)
is not a valid range or ifIt
is not a random-access iterator. This function differs significantly from the C++20 definition since the concepts ofcontiguous_iterator
andsized_sentinel_for
are not available. Since these concepts are not available until C++20, instead this function does not participate in overload resolution unlessstd::iterator_traits<It>::iterator_category == std::random_access_iterator_tag
. Alsofirst
andlast
must be a matching iterator type. After construction, data() is equal tostd::to_address(first)
, and size() is equal tolast - first
.- Parameters
first – Iterator to the beginning of the view.
last – Iterator to the end of the view (non-inclusive).
-
template<class R>
inline explicit constexpr basic_string_view(R &&r) Constructs a basic_string_view.
Constructs a basic_string_view over the “range”
r
. After construction data() is equal tor.data()
and size() is equal tor.size()
.- Template Parameters
R – A range type. Since this implementation is for pre-C++20 and ranges are not available, this is an approximation of a
range
: This type must havedata()
andsize()
member functions that must be convertible to const_pointer and size_type respectively. (e.g. astd::vector
).- Parameters
r – The range to view. Behavior is undefined if
[range.data(), range.size())
is not a contiguous range or cannot be borrowed (i.e. it is a temporary that will expire leaving a dangling pointer).
-
template<class S, class Allocator = typename S::allocator_type, std::enable_if_t<std::is_same<std::basic_string<CharT, Traits, Allocator>, std::decay_t<S>>::value, bool> = false>
inline constexpr basic_string_view(const S &s) Implicit conversion from
std::basic_string
to basic_string_view.Construct a basic_string_view from a
std::basic_string
. The construction is implicit to mimic the behavior of std::basic_string<CharT,Traits,Allocator>::operator basic_string_view.- Template Parameters
S – An instance of
std::basic_string
.
-
constexpr basic_string_view(std::nullptr_t) = delete
basic_string_view cannot be constructed from nullptr.
-
constexpr basic_string_view &operator=(const basic_string_view &view) noexcept = default
Assigns a view.
- Parameters
view – The view to replace
*this
with.- Returns
*this
-
inline constexpr const_iterator begin() const noexcept
Returns an iterator to the beginning.
- Returns
A const_iterator to the first character of the view.
-
inline constexpr const_iterator cbegin() const noexcept
Returns an iterator to the beginning.
- Returns
A const_iterator to the first character of the view.
-
inline constexpr const_iterator end() const noexcept
Returns an iterator to the end.
- Returns
A const_iterator to the character following the last character of the view. This character acts as a placeholder, attempting to access it results in undefined behavior.
-
inline constexpr const_iterator cend() const noexcept
Returns an iterator to the end.
- Returns
A const_iterator to the character following the last character of the view. This character acts as a placeholder, attempting to access it results in undefined behavior.
-
inline constexpr const_reverse_iterator rbegin() const noexcept
Returns a reverse iterator to the beginning.
- Returns
A const_reverse_iterator to the first character of the reversed view. It corresponds to the last character of the non-reversed view.
-
inline constexpr const_reverse_iterator crbegin() const noexcept
Returns a reverse iterator to the beginning.
- Returns
A const_reverse_iterator to the first character of the reversed view. It corresponds to the last character of the non-reversed view.
-
inline constexpr const_reverse_iterator rend() const noexcept
Returns a reverse iterator to the end.
- Returns
a const_reverse_iterator to the character following the last character of the reversed view. It corresponds to the character preceding the first character of the non-reversed view. This character acts as a placeholder, attempting to access it results in undefined behavior.
-
inline constexpr const_reverse_iterator crend() const noexcept
Returns a reverse iterator to the end.
- Returns
a const_reverse_iterator to the character following the last character of the reversed view. It corresponds to the character preceding the first character of the non-reversed view. This character acts as a placeholder, attempting to access it results in undefined behavior.
-
inline constexpr const_reference operator[](size_type pos) const noexcept
Accesses the specified character.
Returns a const reference to the character at the specified position. No bounds checking is performed: the behavior is undefined if
pos >= size()
.- Parameters
pos – The position of the character to return.
- Returns
A const_reference to the requested character.
-
inline constexpr const_reference at(size_type pos) const
Accesses the specified character with bounds checking.
Returns a const reference to the character at the specified position. Bounds checking is performed.
- Throws
std::out_of_range – Invalid access:
pos
is at or after size().- Parameters
pos – The position of the character to return.
- Returns
A const_reference to the requested character
-
inline constexpr const_reference front() const noexcept
Accesses the first character.
- Returns
A const_reference to the first character in the view. The behavior is undefined if empty() is
true
.
-
inline constexpr const_reference back() const noexcept
Accesses the last character.
- Returns
A const_reference to the last character in the view. The behavior is undefined if empty() is
true
.
-
inline constexpr const_pointer data() const noexcept
Returns a pointer to the first character of a view.
Returns a pointer to the underlying character array. The pointer is such that the range
[data(), data() + size())
is valid and the values in it correspond to the values of the view.Note
Unlike
std::basic_string::data()
and string literals, this function returns a pointer to a buffer that is not necessarily null-terminated, for example a substring view (e.g. from remove_suffix()). Therefore, it is typically a mistake to passdata()
to a routine that takes just aconst CharT*
and expects a null- terminated string.- Returns
A const_pointer to the underlying character array.
-
inline constexpr size_type size() const noexcept
Returns the number of characters.
Returns the number of
CharT
characters in the view, i.e.std::distance(begin(), end())
.- Returns
The number of
CharT
elements in the view.
-
inline constexpr size_type length() const noexcept
Returns the number of characters.
Returns the number of
CharT
characters in the view, i.e.std::distance(begin(), end())
.- Returns
The number of
CharT
elements in the view.
-
inline constexpr size_type max_size() const noexcept
Returns the maximum number of characters.
The largest possible number of char-like objects that can be referred to by a basic_string_view.
- Returns
Maximum number of characters.
-
inline constexpr bool empty() const noexcept
Checks whether the view is empty.
Checks if the view has no characters, i.e. whether size() is
0
.- Returns
true
if the view is empty,false
otherwise.
-
inline constexpr void remove_prefix(size_type n) noexcept
Shrinks the view by moving its start forward.
Moves the start of the view forward by
n
characters. The behavior is undefined ifn > size()
.- Parameters
n – Number of characters to remove from the start of the view.
-
inline constexpr void remove_suffix(size_type n) noexcept
Shrinks the view by moving its end backward.
Moves the end of the view back by
n
characters. The behavior is undefined ifn > size()
.- Parameters
n – Number of characters to remove from the end of the view.
-
inline constexpr void swap(basic_string_view &v) noexcept
Swaps the contents.
Exchanges the view with that of
v
.- Parameters
v – View to swap with.
-
inline constexpr size_type copy(CharT *dest, size_type count, size_type pos = 0) const
Copies characters.
Copies the substring
[pos, pos + rcount)
to the character array pointed to bydest
, wherercount
is the smaller ofcount
andsize() - pos
. Equivalent toTraits::copy(dest, data() + pos, rcount)
.
-
inline constexpr basic_string_view substr(size_t pos, size_t count = npos) const
Returns a substring.
Returns a view of the substring
[pos, pos + rcount)
, wherercount
is the smaller ofcount
andsize() - pos.
-
inline constexpr int compare(basic_string_view v) const noexcept
Compares two views.
The length rlen of the sequences to compare is the smaller of size() and
v.size()
. The function compares the two views by callingtraits::compare(data(), v.data(), rlen)
, and returns as follows:A value less than zero (
<0
) if:A value of zero (
0
) if:A value greater than zero (
>0
) if:
- Parameters
v – View to compare
- Returns
A negative value if
*this
is less than the other character sequence,0
if both character sequences are equal, positive value if*this
is greater than the other character sequence. See above.
-
inline constexpr int compare(size_type pos1, size_type count1, basic_string_view v) const
Compares two views.
Equivalent to
substr(pos1, count1).compare(v)
.See also
compare(basic_string_view) const noexcept, substr()
- Throws
- Parameters
pos1 – Position of the first character in this view to compare.
count1 – Number of characters of this view to compare.
v – View to compare.
- Returns
see compare(basic_string_view) const noexcept
-
inline constexpr int compare(size_type pos1, size_type count1, basic_string_view v, size_type pos2, size_type count2) const
Compares two views.
Equivalent to
substr(pos1, count1).compare(v.substr(pos2, count2))
.See also
compare(basic_string_view) const noexcept, substr()
- Throws
- Parameters
pos1 – Position of the first character in this view to compare.
count1 – Number of characters of this view to compare.
v – View to compare.
pos2 – Position of the first character of the given view to compare.
count2 – Number of characters of the given view to compare.
- Returns
see compare(basic_string_view) const noexcept
-
inline constexpr int compare(const CharT *s) const
Compares two views.
Equivalent to
compare(basic_string_view(s))
.See also
compare(basic_string_view) const noexcept
- Parameters
s – Pointer to the null-terminated character string to compare to.
- Returns
see compare(basic_string_view) const noexcept
-
inline constexpr int compare(size_type pos1, size_type count1, const CharT *s) const
Compares two views.
Equivalent to
substr(pos1, count1).compare(basic_string_view(s))
.See also
compare(basic_string_view) const noexcept, substr()
- Throws
- Parameters
pos1 – Position of the first character in this view to compare.
count1 – Number of characters of this view to compare.
s – Pointer to the null-terminated character string to compare to.
- Returns
see compare(basic_string_view) const noexcept
-
inline constexpr int compare(size_type pos1, size_type count1, const CharT *s, size_type count2) const
Compares two views.
Equivalent to
substr(pos1, count1).compare(basic_string_view(s, count2))
. Behavior is undefined if[s, s+count2)
is not a valid contiguous range.See also
compare(basic_string_view) const noexcept, substr()
- Throws
- Parameters
pos1 – Position of the first character in this view to compare.
count1 – Number of characters of this view to compare.
s – Pointer to the character string to compare to.
count2 – Number of characters of
s
to compare.
- Returns
see compare(basic_string_view) const noexcept
-
inline constexpr bool starts_with(basic_string_view sv) const noexcept
Checks if the string view starts with the given prefix.
Effectively returns
substr(0, sv.size()) == sv
.- Parameters
sv – A string view which may be a result of implicit conversion from
std::basic_string
.- Returns
true
if the string view begins with the provided prefix,false
otherwise.
-
inline constexpr bool starts_with(CharT ch) const noexcept
Checks if the string view starts with the given prefix.
Effectively returns
!empty() && Traits::eq(front(), ch)
.- Parameters
ch – A single character.
- Returns
true
if the string view begins with the provided prefix,false
otherwise.
-
inline constexpr bool starts_with(const CharT *s) const
Checks if the string view starts with the given prefix.
Effectively returns
starts_with(basic_string_view(s))
.- Parameters
s – A null-terminated character string.
- Returns
true
if the string view begins with the provided prefix,false
otherwise.
-
inline constexpr bool ends_with(basic_string_view sv) const noexcept
Checks if the string view ends with the given suffix.
Effectively returns
size() >= sv.size() && compare(size() - sv.size(), npos, sv) == 0
.- Parameters
sv – A string view which may be a result of implicit conversion from
std::basic_string
.- Returns
true
if the string view ends with the provided suffix,false
otherwise.
-
inline constexpr bool ends_with(CharT ch) const noexcept
Checks if the string view ends with the given suffix.
Effectively returns
!empty() && Traits::eq(back(), ch)
.- Parameters
ch – A single character.
- Returns
true
if the string view ends with the provided suffix,false
otherwise.
-
inline constexpr bool ends_with(const CharT *s) const
Checks if the string view ends with the given suffix.
Effectively returns
ends_with(basic_string_view(s))
.- Parameters
s – A null-terminated character string.
- Returns
true
if the string view ends with the provided suffix,false
otherwise.
-
inline constexpr bool contains(basic_string_view sv) const noexcept
Checks if the string view contains the given substring or character.
Effectively
find(sv) != npos
.- Parameters
sv – A string view.
- Returns
true
if the string view contains the provided substring,false
otherwise.
-
inline constexpr bool contains(CharT c) const noexcept
Checks if the string view contains the given substring or character.
Effectively
find(c) != npos
.- Parameters
c – A single character.
- Returns
true
if the string view contains the provided substring,false
otherwise.
-
inline constexpr bool contains(const CharT *s) const
Checks if the string view contains the given substring or character.
Effectively
find(s) != npos
.- Parameters
s – A null-terminated character string.
- Returns
true
if the string view contains the provided substring,false
otherwise.
-
inline constexpr size_type find(basic_string_view v, size_type pos = 0) const noexcept
Find characters in the view.
Finds the first substring equal to the given character sequence. Complexity is
O(size() * v.size())
at worst.- Parameters
v – View to search for.
pos – Position at which to start the search.
- Returns
Position of the first character of the found substring, or npos if no such substring is found.
-
inline constexpr size_type find(CharT ch, size_type pos = 0) const noexcept
Find characters in the view.
Finds the first substring equal to the given character sequence. Equivalent to
find(basic_string_view(std::addressof(ch), 1))
. Complexity isO(size())
at worst.- Parameters
ch – Character to search for.
pos – Position at which to start the search.
- Returns
Position of the first character of the found substring, or npos if no such substring is found.
-
inline constexpr size_type find(const CharT *s, size_type pos, size_type count) const
Find characters in the view.
Finds the first substring equal to the given character sequence. Equivalent to
find(basic_string_view(s, count), pos)
. Complexity isO(size() * count)
at worst.- Parameters
s – Pointer to a character string to search for.
pos – Position at which to start the search.
count – Length of substring to search for.
- Returns
Position of the first character of the found substring, or npos if no such substring is found.
-
inline constexpr size_type find(const CharT *s, size_type pos = 0) const
Find characters in the view.
Finds the first substring equal to the given character sequence. Equivalent to
find(basic_string_view(s), pos)
. Complexity isO(size() * Traits::length(s))
at worst.- Parameters
s – Pointer to a character string to search for.
pos – Position at which to start the search.
- Returns
Position of the first character of the found substring, or npos if no such substring is found.
-
inline constexpr size_type rfind(basic_string_view v, size_type pos = npos) const noexcept
Find the last occurrence of a substring.
Finds the last substring equal to the given character sequence. Search begins at
pos
, i.e. the found substring must not being is a position followingpos
. If npos or any value not smaller thansize()-1
is passed as pos, the whole string will be searched. Complexity isO(size() * v.size())
at worst.- Parameters
v – View to search for.
pos – Position at which to start the search.
- Returns
Position of the first character of the found substring, or npos if no such substring is found.
-
inline constexpr size_type rfind(CharT ch, size_type pos = npos) const noexcept
Find the last occurrence of a substring.
Finds the last substring equal to the given character sequence. Search begins at
pos
, i.e. the found substring must not being is a position followingpos
. If npos or any value not smaller thansize()-1
is passed as pos, the whole string will be searched. Equivalent torfind(basic_string_view(std::addressof(ch), 1), pos)
. Complexity isO(size())
at worst.- Parameters
ch – Character to search for.
pos – Position at which to start the search.
- Returns
Position of the first character of the found substring, or npos if no such substring is found.
-
inline constexpr size_type rfind(const CharT *s, size_type pos, size_type count) const
Find the last occurrence of a substring.
Finds the last substring equal to the given character sequence. Search begins at
pos
, i.e. the found substring must not being is a position followingpos
. If npos or any value not smaller thansize()-1
is passed as pos, the whole string will be searched. Equivalent torfind(basic_string_view(s, count), pos)
. Complexity isO(size() * count)
at worst.- Parameters
s – Pointer to a character string to search for.
pos – Position at which to start the search.
count – Length of substring to search for.
- Returns
Position of the first character of the found substring, or npos if no such substring is found.
-
inline constexpr size_type rfind(const CharT *s, size_type pos = npos) const
Find the last occurrence of a substring.
Finds the last substring equal to the given character sequence. Search begins at
pos
, i.e. the found substring must not being is a position followingpos
. If npos or any value not smaller thansize()-1
is passed as pos, the whole string will be searched. Equivalent torfind(basic_string_view(s), pos)
. Complexity isO(size() * Traits::length(s))
at worst.- Parameters
s – Pointer to a null-terminated character string to search for.
pos – Position at which to start the search.
- Returns
Position of the first character of the found substring, or npos if no such substring is found.
-
inline constexpr size_type find_first_of(basic_string_view v, size_type pos = 0) const noexcept
Find first occurrence of characters.
Finds the first occurrence of any of the characters of
v
in this view, starting as positionpos
. Complexity isO(size() * v.size())
at worst.- Parameters
v – View to search for.
pos – Position at which to start the search.
- Returns
Position of the first occurrence of any character of the substring, or npos if no such character is found.
-
inline constexpr size_type find_first_of(CharT ch, size_type pos = 0) const noexcept
Find first occurrence of characters.
Equivalent to
find_first_of(basic_string_view(std::addressof(ch), 1), pos)
. Complexity isO(size())
at worst.See also
- Parameters
ch – Character to search for.
pos – Position at which to start the search.
- Returns
Position of the first occurrence of any character of the substring, or npos if no such character is found.
-
inline constexpr size_type find_first_of(const CharT *s, size_type pos, size_type count) const
Find first occurrence of characters.
Equivalent to
find_first_of(basic_string_view(s, count), pos)
. Complexity isO(size() * count)
at worst.See also
- Parameters
s – Pointer to a string of characters to search for.
pos – Position at which to start the search.
count – Length of the string of characters to search for.
- Returns
Position of the first occurrence of any character of the substring, or npos if no such character is found.
-
inline constexpr size_type find_first_of(const CharT *s, size_type pos = 0) const
Find first occurrence of characters.
Equivalent to
find_first_of(basic_string_view(s, Traits::length(s)), pos)
. Complexity isO(size() * count)
at worst.See also
- Parameters
s – Pointer to a null-terminated string of characters to search for.
pos – Position at which to start the search.
- Returns
Position of the first occurrence of any character of the substring, or npos if no such character is found.
-
inline constexpr size_type find_last_of(basic_string_view v, size_type pos = npos) const noexcept
Find last occurrence of characters.
Finds the last character equal to one of characters in the given character sequence. Exact search algorithm is not specified. The search considers only the interval
[0, pos]
. If the character is not present in the interval, npos will be returned. Complexity isO(size() * v.size())
at worst.- Parameters
v – View to search for.
pos – Position at which the search is to finish.
- Returns
Position of the last occurrence of any character of the substring, or npos if no such character is found.
-
inline constexpr size_type find_last_of(CharT ch, size_type pos = npos) const noexcept
Find last occurrence of characters.
Finds the last character equal to one of characters in the given character sequence. Exact search algorithm is not specified. The search considers only the interval
[0, pos]
. If the character is not present in the interval, npos will be returned. Equivalent tofind_last_of(basic_string_view(std::addressof(ch), 1), pos)
. Complexity isO(size())
at worst.See also
- Parameters
ch – Character to search for.
pos – Position at which the search is to finish.
- Returns
Position of the last occurrence of any character of the substring, or npos if no such character is found.
-
inline constexpr size_type find_last_of(const CharT *s, size_type pos, size_type count) const
Find last occurrence of characters.
Finds the last character equal to one of characters in the given character sequence. Exact search algorithm is not specified. The search considers only the interval
[0, pos]
. If the character is not present in the interval, npos will be returned. Equivalent tofind_last_of(basic_string_view(s, count), pos)
. Complexity isO(size() * count)
at worst.See also
- Parameters
s – Pointer to a string of characters to search for.
pos – Position at which the search is to finish.
count – Length of the string of characters to search for.
- Returns
Position of the last occurrence of any character of the substring, or npos if no such character is found.
-
inline constexpr size_type find_last_of(const CharT *s, size_type pos = npos) const
Find last occurrence of characters.
Finds the last character equal to one of characters in the given character sequence. Exact search algorithm is not specified. The search considers only the interval
[0, pos]
. If the character is not present in the interval, npos will be returned. Equivalent tofind_last_of(basic_string_view(s), pos)
. Complexity isO(size() * Traits::length(s))
at worst.See also
- Parameters
s – Pointer to a null-terminated string of characters to search for.
pos – Position at which the search is to finish.
- Returns
Position of the last occurrence of any character of the substring, or npos if no such character is found.
-
inline constexpr size_type find_first_not_of(basic_string_view v, size_type pos = 0) const noexcept
Find first absence of characters.
Finds the first character not equal to any of the characters in the given character sequence. Complexity is
O(size() * v.size())
at worst.- Parameters
v – View to search for.
pos – Position at which to start the search.
- Returns
Position of the first character not equal to any of the characters in the given string, or npos if no such character is found.
-
inline constexpr size_type find_first_not_of(CharT ch, size_type pos = 0) const noexcept
Find first absence of characters.
Finds the first character not equal to any of the characters in the given character sequence. Equivalent to
find_first_not_of(basic_string_view(std::addressof(ch), 1), pos)
. Complexity isO(size())
at worst.See also
find_first_not_of(basic_string_view,size_type) const noexcept
- Parameters
ch – Character to search for.
pos – Position at which to start the search.
- Returns
Position of the first character not equal to any of the characters in the given string, or npos if no such character is found.
-
inline constexpr size_type find_first_not_of(const CharT *s, size_type pos, size_type count) const
Find first absence of characters.
Finds the first character not equal to any of the characters in the given character sequence. Equivalent to
find_first_not_of(basic_string_view(s, count), pos)
. Complexity isO(size() * count)
at worst.See also
find_first_not_of(basic_string_view,size_type) const noexcept
- Parameters
s – Pointer to a string of characters to search for.
pos – Position at which to start the search.
count – Length of the string of characters to compare.
- Returns
Position of the first character not equal to any of the characters in the given string, or npos if no such character is found.
-
inline constexpr size_type find_first_not_of(const CharT *s, size_type pos = 0) const
Find first absence of characters.
Finds the first character not equal to any of the characters in the given character sequence. Equivalent to
find_first_not_of(basic_string_view(s), pos)
. Complexity isO(size() * Traits::length(s))
at worst.See also
find_first_not_of(basic_string_view,size_type) const noexcept
- Parameters
s – Pointer to a null-terminated string of characters to search for.
pos – Position at which to start the search.
- Returns
Position of the first character not equal to any of the characters in the given string, or npos if no such character is found.
-
inline constexpr size_type find_last_not_of(basic_string_view v, size_type pos = 0) const noexcept
Find last absence of characters.
Finds the last character not equal to any of the characters in the given character sequence. The search considers only the interval
[0, pos]
. Complexity isO(size() * v.size())
at worst.- Parameters
v – View to search for.
pos – Position at which to start the search.
- Returns
Position of the last character not equal to any of the characters in the given string, or npos if no such character is found.
-
inline constexpr size_type find_last_not_of(CharT ch, size_type pos = 0) const noexcept
Find last absence of characters.
Finds the last character not equal to any of the characters in the given character sequence. The search considers only the interval
[0, pos]
. Equivalent tofind_last_not_of(basic_string_view(std::addressof(ch), 1), pos)
, Complexity isO(size())
at worst.See also
find_last_not_of(basic_string_view,size_type) const noexcept
- Parameters
ch – Character to search for.
pos – Position at which to start the search.
- Returns
Position of the last character not equal to any of the characters in the given string, or npos if no such character is found.
-
inline constexpr size_type find_last_not_of(const CharT *s, size_type pos, size_type count) const
Find last absence of characters.
Finds the last character not equal to any of the characters in the given character sequence. The search considers only the interval
[0, pos]
. Equivalent tofind_last_not_of(basic_string_view(s, count), pos)
, Complexity isO(size() * count)
at worst.See also
find_last_not_of(basic_string_view,size_type) const noexcept
- Parameters
s – Pointer to a string of characters to compare.
pos – Position at which to start the search.
count – Length of the string of characters to compare.
- Returns
Position of the last character not equal to any of the characters in the given string, or npos if no such character is found.
-
inline constexpr size_type find_last_not_of(const CharT *s, size_type pos = 0) const
Find last absence of characters.
Finds the last character not equal to any of the characters in the given character sequence. The search considers only the interval
[0, pos]
. Equivalent tofind_last_not_of(basic_string_view(s), pos)
, Complexity isO(size() * Traits::length(s))
at worst.See also
find_last_not_of(basic_string_view,size_type) const noexcept
- Parameters
s – Pointer to a null-terminated string of characters to compare.
pos – Position at which to start the search.
- Returns
Position of the last character not equal to any of the characters in the given string, or npos if no such character is found.