Skip to main content

fixstr::basic_fixed_string::find

1#
template <size_t M>[[nodiscard]] constexpr size_type find(const same_with_other_size<M>& str, size_type pos = npos) const noexcept;
2#
 [[nodiscard]] constexpr size_type find(string_view_type sv, size_type pos = 0) const noexcept;
3#
[[nodiscard]] constexpr size_type find(const value_type* s, size_type pos, size_type n) const;
4#
[[nodiscard]] constexpr size_type find(const value_type* s, size_type pos = 0) const;
5#
[[nodiscard]] constexpr size_type find(value_type c, size_type pos = 0) const noexcept;

Finds the first substring equal to the given character sequence. Search begins at pos, i.e. the found substring must not begin in a position preceding pos.

  1. Finds the first substring equal to str.

  2. Finds the first substring equal to sv.

  3. Finds the first substring equal to the range [s, s + n). This range may contain null characters.

  4. Finds the first substring equal to the character string pointed to by s. The length of the string is determined by the first null character using TTraits::length(s).

  5. Finds the first character ch.

Parameters#

  • str - string to search for
  • sv - string view to search for
  • pos - position at which to start the search
  • n - length of substring to search for
  • s - pointer to a character string to search for
  • ch - character to search for

Return value#

Position of the first character of the found substring or npos if no such substring is found.

Complexity#

Linear in size().

Example#

#include <fixed_string.hpp>#include <iostream>#include <string>
template <auto n>void print(auto s) {    if constexpr (n == decltype(s)::npos) {        std::cout << "not found\n";    } else {        std::cout << "found: " << s.template substr<n>() << '\n';    }}
int main() {    constexpr fixstr::fixed_string s = "This is a string";
    // search from beginning of string    constexpr auto n1 = s.find("is");    print<n1>(s);
    // search from position 5    constexpr auto n2 = s.find("is", 5);    print<n2>(s);
    // find a single character    constexpr auto n3 = s.find('a');    print<n3>(s);
    // find a single character    constexpr auto n4 = s.find('q');    print<n4>(s);}