File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ cmake_minimum_required (VERSION 3.30 )
2+
3+ project (main)
4+
5+ set (CMAKE_CXX_STANDARD 23)
6+ set (CMAKE_CXX_COMPILER g++-14)
7+ set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
8+
9+ set (SOURCES
10+ main.cpp
11+ )
12+
13+ include_directories (
14+ /usr/local/include
15+ /opt/homebrew/include
16+ ${CMAKE_CURRENT_SOURCE_DIR}
17+ )
18+
19+ link_directories (
20+ /usr/local/lib
21+ /opt/homebrew/lib
22+ )
23+
24+ add_executable (main
25+ ${SOURCES}
26+ )
Original file line number Diff line number Diff line change 1+ #include < iostream>
2+ #include < expected>
3+
4+ using namespace std ;
5+
6+ enum class error
7+ {
8+ compile_time_error,
9+ runtime_error
10+ };
11+
12+ auto unexpected_runtime_error () -> expected<int, error>
13+ {
14+ return unexpected (error::runtime_error);
15+ }
16+
17+ int main (int argc, char * argv[])
18+ {
19+ expected<double , int > ex = unexpected (3 );
20+
21+ if (!ex)
22+ cout << " ex contains an error\n " ;
23+
24+ if (ex == unexpected (3 ))
25+ cout << " The error value is equal to 3\n " ;
26+
27+ const auto e = unexpected_runtime_error ();
28+ e.and_then ([](const auto & e) -> expected<int , error>
29+ {
30+ cout << " and_then" << int (e);
31+ return {};
32+ })
33+ .or_else ([](const auto & e) -> expected<int , error>
34+ {
35+ cout << " or_else: " << int (e);
36+ return {};
37+ });
38+
39+ return 0 ;
40+ }
Original file line number Diff line number Diff line change @@ -22,7 +22,6 @@ int main(int argc, const char *argv[])
2222
2323
2424 // 2. to ucs2
25-
2625 wstring_convert<codecvt_utf8<char16_t >, char16_t > ucs2conv;
2726 try
2827 {
@@ -35,7 +34,6 @@ int main(int argc, const char *argv[])
3534 << " characters:\n " ;
3635
3736 for (char16_t c : ucs2) cout << hex << showbase << c << ' \n ' ;
38-
3937 }
4038
4139 return 0 ;
You can’t perform that action at this time.
0 commit comments