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 as CharT or the program is ill-formed.

Subclassed by omni::structuredlog::BasicStringView< CharT, Traits >

Public Types

using traits_type = Traits

Traits

using value_type = CharT

CharT

using pointer = CharT*

CharT*

using const_pointer = const CharT*

const CharT*

using reference = CharT&

CharT&

using const_reference = const CharT&

const CharT&

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 and const_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

using size_type = std::size_t

std::size_t

using difference_type = std::ptrdiff_t

std::ptrdiff_t

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 to 0.

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 to other.data() and size() is equal to other.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 to s, and size() is equal to count.

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 by Traits::length(s). The behavior is undefined if [s, s + Traits::length(s)) is not a valid range. After construction, data() is equal to s, and size() is equal to Traits::length(s).

Note

As a Carbonite extension, this constructor will not participate in overload resolution if s is a literal CharT 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 by N - 1 as literal strings will have a terminating null character. After construction, data() is equal to literal, and size() is equal to N - 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 if It is not a random-access iterator. This function differs significantly from the C++20 definition since the concepts of contiguous_iterator and sized_sentinel_for are not available. Since these concepts are not available until C++20, instead this function does not participate in overload resolution unless std::iterator_traits<It>::iterator_category == std::random_access_iterator_tag. Also first and last must be a matching iterator type. After construction, data() is equal to std::to_address(first), and size() is equal to last - 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 to r.data() and size() is equal to r.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 have data() and size() member functions that must be convertible to const_pointer and size_type respectively. (e.g. a std::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 pass data() to a routine that takes just a const 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 if n > 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 if n > 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 by dest, where rcount is the smaller of count and size() - pos. Equivalent to Traits::copy(dest, data() + pos, rcount).

Throws

std::out_of_range – if pos > size().

Parameters
  • dest – Pointer to the destination character string.

  • count – Requested substring length.

  • pos – Position of first character.

Returns

Number of characters copied.

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), where rcount is the smaller of count and size() - pos.

Throws

std::out_of_range – if pos > size().

Parameters
  • pos – Position of the first character.

  • count – Requested length.

Returns

View of the substring [pos, pos + count).

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 calling traits::compare(data(), v.data(), rlen), and returns as follows:

  • A value less than zero (<0) if:

    • Traits::compare(data(), v.data(), rlen) < 0, or

    • Traits::compare(data(), v.data(), rlen) == 0 and size() < v.size().

  • A value of zero (0) if:

    • Traits::compare(data(), v.data(), rlen) == 0 and size() == v.size().

  • A value greater than zero (>0) if:

    • Traits::compare(data(), v.data(), rlen) > 0, or

    • Traits::compare(data(), v.data(), rlen) == 0 and size() > v.size().

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).

Throws

std::out_of_range – if pos1 > size().

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)).

Throws

std::out_of_range – if pos1 > size() or if pos2 > v.size().

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)).

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)).

Throws

std::out_of_range – if pos1 > size().

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.

Throws

std::out_of_range – if pos1 > size().

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 is O(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 is O(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 is O(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 following pos. If npos or any value not smaller than size()-1 is passed as pos, the whole string will be searched. 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 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 following pos. If npos or any value not smaller than size()-1 is passed as pos, the whole string will be searched. Equivalent to rfind(basic_string_view(std::addressof(ch), 1), pos). Complexity is O(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 following pos. If npos or any value not smaller than size()-1 is passed as pos, the whole string will be searched. Equivalent to rfind(basic_string_view(s, count), pos). Complexity is O(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 following pos. If npos or any value not smaller than size()-1 is passed as pos, the whole string will be searched. Equivalent to rfind(basic_string_view(s), pos). Complexity is O(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 position pos. 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 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 is O(size()) at worst.

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 is O(size() * count) at worst.

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 is O(size() * count) at worst.

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 is O(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 to find_last_of(basic_string_view(std::addressof(ch), 1), pos). Complexity is O(size()) at worst.

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 to find_last_of(basic_string_view(s, count), pos). Complexity is O(size() * count) at worst.

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 to find_last_of(basic_string_view(s), pos). Complexity is O(size() * Traits::length(s)) at worst.

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 is O(size()) at worst.

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 is O(size() * count) at worst.

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 is O(size() * Traits::length(s)) at worst.

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 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 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 to find_last_not_of(basic_string_view(std::addressof(ch), 1), pos), Complexity is O(size()) at worst.

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 to find_last_not_of(basic_string_view(s, count), pos), Complexity is O(size() * count) at worst.

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 to find_last_not_of(basic_string_view(s), pos), Complexity is O(size() * Traits::length(s)) at worst.

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.

Public Static Attributes

static constexpr size_type npos = size_type(-1)

Special value. The exact meaning depends on the context.