-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain.cpp
More file actions
40 lines (32 loc) · 722 Bytes
/
main.cpp
File metadata and controls
40 lines (32 loc) · 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <expected>
using namespace std;
enum class error
{
compile_time_error,
runtime_error
};
auto unexpected_runtime_error() -> expected<int, error>
{
return unexpected(error::runtime_error);
}
int main(int argc, char* argv[])
{
expected<double, int> ex = unexpected(3);
if (!ex)
cout << "ex contains an error\n";
if (ex == unexpected(3))
cout << "The error value is equal to 3\n";
const auto e = unexpected_runtime_error();
e.and_then([](const auto& e) -> expected<int, error>
{
cout << "and_then" << int(e);
return {};
})
.or_else([](const auto& e) -> expected<int, error>
{
cout << "or_else: " << int(e);
return {};
});
return 0;
}