fixstr::basic_fixed_string::find
#1 |
| |
#2 |
| |
#3 |
| |
#4 |
| |
#5 |
|
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
.
Finds the first substring equal to
str
.Finds the first substring equal to
sv
.Finds the first substring equal to the range
[s, s + n)
. This range may contain null characters.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)
.Finds the first character
ch
.
#
Parametersstr
- string to search forsv
- string view to search forpos
- position at which to start the searchn
- length of substring to search fors
- pointer to a character string to search forch
- character to search for
#
Return valuePosition of the first character of the found substring or npos
if no such substring is found.
#
ComplexityLinear 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);}