blob: be93a077aa7c8be3dc312269f00f9927a706d2c5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#include <result.h>
enum ErrorX { one, two = 5, three, NoError };
// operator bool
static_assert(!(Result<int, ErrorX>{ErrorX::one}));
static_assert(!(Result<int, ErrorX>{ErrorX::two}));
static_assert((Result<int, ErrorX>{5}));
// error
static_assert((Result<int, ErrorX>{ErrorX::one}).error() == ErrorX::one);
static_assert((Result<int, ErrorX>{5}).error() == ErrorX::NoError);
// value
static_assert((Result<int, ErrorX>{ErrorX::one}).value() == int{});
static_assert((Result<int, ErrorX>{5}).value() == 5);
|