00 // 01 // Example of optional 02 // 03 04 #include <optional> 05 #include <string> 06 #include <iostream> 07 08 std::optional<int> toInt(const std::string& s) 09 { 10 try { 11 return std::stoi(s); 12 } 13 catch (...) { 14 return std::nullopt; 15 } 16 } 17 18 void report(const std::string& s) 19 { 20 auto value = toInt(s); 21 if(value) 22 std::cout << *value << '\n'; 23 else 24 std::cout << "It is not integer\n"; 25 } 26 27