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

Function main

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

Source from the content-addressed store, hash-verified

11}
12
13int main()
14{
15 std::string s{ "133" };
16
17 auto pos = FindInStr(s, [](char ch) {
18 return ch >= '0' && ch <= '9' && (ch - '0') % 2 == 0;
19 });
20
21 auto ch = pos.transform([&s](auto idx) {
22 std::println("The first occurence: {}", s[idx]);
23 return s[idx];
24 })
25 .or_else([]() {
26 std::println("Not find any occurence");
27 return std::optional{ '?' };
28 });
29
30 std::println("Get char: {}", *ch);
31
32 return 0;
33}

Callers

nothing calls this directly

Calls 1

FindInStrFunction · 0.85

Tested by

no test coverage detected