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

Function main

07-Error Handling/code/expected.cpp:22–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20}
21
22int main()
23{
24 auto process = [](std::string_view str) {
25 std::print("str: {:?}, ", str);
26 parse_number(str)
27 .transform([](double val) {
28 std::println("value: {}", val);
29 return val;
30 })
31 .transform_error([](std::errc err) {
32 if (err == std::errc::invalid_argument)
33 std::println("error: invalid input");
34 else if (err == std::errc::result_out_of_range)
35 std::println("error: overflow");
36 return err;
37 });
38 };
39
40 for (auto src : { "42", "42abc", "meow", "inf" })
41 process(src);
42 return 0;
43}

Callers

nothing calls this directly

Calls 2

printFunction · 0.85
parse_numberFunction · 0.85

Tested by

no test coverage detected