21 Strings library [strings]

21.4 String view classes [string.view]

21.4.2 Class template basic_string_view [string.view.template]

21.4.2.7 Searching [string.view.find]

This section specifies the basic_string_view member functions named find, rfind, find_first_of, find_last_of, find_first_not_of, and find_last_not_of.

Member functions in this section have complexity Ο(size() * str.size()) at worst, although implementations are encouraged to do better.

Each member function of the form

constexpr return-type F(const charT* s, size_type pos);

is equivalent to return F(basic_string_view(s), pos);

Each member function of the form

constexpr return-type F(const charT* s, size_type pos, size_type n);

is equivalent to return F(basic_string_view(s, n), pos);

Each member function of the form

constexpr return-type F(charT c, size_type pos);

is equivalent to return F(basic_string_view(&c, 1), pos);

constexpr size_type find(basic_string_view str, size_type pos = 0) const noexcept;

Let xpos be the lowest position, if possible, such that the following conditions hold:

  • pos <= xpos

  • xpos + str.size() <= size()

  • traits::eq(at(xpos + I), str.at(I)) for all elements I of the string referenced by str.

Effects: Determines xpos.

Returns: xpos if the function can determine such a value for xpos. Otherwise, returns npos.

Remarks: Uses traits::eq().

constexpr size_type rfind(basic_string_view str, size_type pos = npos) const noexcept;

Let xpos be the highest position, if possible, such that the following conditions hold:

  • xpos <= pos

  • xpos + str.size() <= size()

  • traits::eq(at(xpos + I), str.at(I)) for all elements I of the string referenced by str.

Effects: Determines xpos.

Returns: xpos if the function can determine such a value for xpos. Otherwise, returns npos.

Remarks: Uses traits::eq().

constexpr size_type find_first_of(basic_string_view str, size_type pos = 0) const noexcept;

Let xpos be the lowest position, if possible, such that the following conditions hold:

  • pos <= xpos

  • xpos < size()

  • traits::eq(at(xpos), str.at(I)) for some element I of the string referenced by str.

Effects: Determines xpos.

Returns: xpos if the function can determine such a value for xpos. Otherwise, returns npos.

Remarks: Uses traits::eq().

constexpr size_type find_last_of(basic_string_view str, size_type pos = npos) const noexcept;

Let xpos be the highest position, if possible, such that the following conditions hold:

  • xpos <= pos

  • xpos < size()

  • traits::eq(at(xpos), str.at(I)) for some element I of the string referenced by str.

Effects: Determines xpos.

Returns: xpos if the function can determine such a value for xpos. Otherwise, returns npos.

Remarks: Uses traits::eq().

constexpr size_type find_first_not_of(basic_string_view str, size_type pos = 0) const noexcept;

Let xpos be the lowest position, if possible, such that the following conditions hold:

  • pos <= xpos

  • xpos < size()

  • traits::eq(at(xpos), str.at(I)) for no element I of the string referenced by str.

Effects: Determines xpos.

Returns: xpos if the function can determine such a value for xpos. Otherwise, returns npos.

Remarks: Uses traits::eq().

constexpr size_type find_last_not_of(basic_string_view str, size_type pos = npos) const noexcept;

Let xpos the highest position, if possible, such that the following conditions hold:

  • xpos <= pos

  • xpos < size()

  • traits::eq(at(xpos), str.at(I)) for no element I of the string referenced by str.

Effects: Determines xpos.

Returns: xpos if the function can determine such a value for xpos. Otherwise, returns npos.

Remarks: Uses traits::eq().