emlabcpp
modern opinionated embedded C++ library
outcome.h
Go to the documentation of this file.
1 #pragma once
23 
24 #include "./result.h"
25 #include "./status.h"
26 
27 namespace emlabcpp
28 {
29 
30 enum class outcome_e : uint8_t
31 {
32  SUCCESS = 0,
33  FAILURE = 1,
34  ERROR = 2,
35 };
36 
48 struct [[nodiscard]] outcome : status< outcome, outcome_e >
49 {
50  using status::status;
51  using enum outcome_e;
52 
53  constexpr outcome( result const r ) noexcept
54  : status( r == result::SUCCESS ? outcome_e::SUCCESS : outcome_e::ERROR )
55  {
56  }
57 
58  constexpr outcome( result_e const r ) noexcept
59  : status( r == result::SUCCESS ? outcome_e::SUCCESS : outcome_e::ERROR )
60  {
61  }
62 
63  constexpr operator result() const noexcept
64  {
65  return value() == outcome_e::SUCCESS ? result::SUCCESS : result::ERROR;
66  }
67 };
68 
69 } // namespace emlabcpp
MIT License.
Definition: impl.h:31
outcome_e
Definition: outcome.h:31
result_e
Definition: result.h:33
outcome represents tristate resut of some operation, which can succeed, fail or produce an error.
Definition: outcome.h:49
constexpr outcome(result_e const r) noexcept
Definition: outcome.h:58
constexpr outcome(result const r) noexcept
Definition: outcome.h:53
result represents an result of some operation, as an alternative to returning just bool with true/fal...
Definition: result.h:42
Definition: status.h:31
constexpr status(enum_type s) noexcept
Definition: status.h:34