diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2021-03-12 16:44:02 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2021-03-12 16:44:02 +0200 |
commit | b7f5d7565a19efbfebd72f2877444c552e4230c8 (patch) | |
tree | e17ec2edc3be86672442ca1ab854f21cb566b598 /libk/test/result.cc | |
parent | vmm: map multiboot structs (diff) | |
download | kernel.cpp-b7f5d7565a19efbfebd72f2877444c552e4230c8.tar.xz |
libk: add Result<T, E> class
Diffstat (limited to 'libk/test/result.cc')
-rw-r--r-- | libk/test/result.cc | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/libk/test/result.cc b/libk/test/result.cc new file mode 100644 index 0000000..be93a07 --- /dev/null +++ b/libk/test/result.cc @@ -0,0 +1,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); |