MCPcopy Create free account
hub / github.com/Extra-Creativity/Modern-Cpp-Basics / FindInStr

Function FindInStr

07-Error Handling/code/optional.cpp:6–11  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#include <string>
5
6std::optional<std::size_t> FindInStr(const std::string &str, auto pred)
7{
8 // Of course, you can add std::reference_wrapper.
9 auto pos = std::ranges::find_if(str, pred);
10 return pos == str.end() ? std::nullopt : std::optional{ pos - str.begin() };
11}
12
13int main()
14{

Callers 1

mainFunction · 0.85

Calls 2

endMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected