MCPcopy Create free account
hub / github.com/awslabs/aws-lambda-cpp / outcome

Class outcome

include/aws/lambda-runtime/outcome.h:24–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22
23template <typename TResult, typename TFailure>
24class outcome {
25public:
26 outcome(TResult const& s) : m_s(s), m_success(true) {}
27 outcome(TResult&& s) : m_s(std::move(s)), m_success(true) {}
28
29 outcome(TFailure const& f) : m_f(f), m_success(false) {}
30 outcome(TFailure&& f) : m_f(std::move(f)), m_success(false) {}
31
32 outcome(outcome const& other) : m_success(other.m_success)
33 {
34 if (m_success) {
35 new (&m_s) TResult(other.m_s);
36 }
37 else {
38 new (&m_f) TFailure(other.m_f);
39 }
40 }
41
42 outcome(outcome&& other) noexcept : m_success(other.m_success)
43 {
44 if (m_success) {
45 new (&m_s) TResult(std::move(other.m_s));
46 }
47 else {
48 new (&m_f) TFailure(std::move(other.m_f));
49 }
50 }
51
52 ~outcome() { destroy(); }
53
54 outcome& operator=(outcome&& other) noexcept
55 {
56 assert(this != &other);
57 destroy();
58 if (other.m_success) {
59 new (&m_s) TResult(std::move(other.m_s));
60 }
61 else {
62 new (&m_f) TFailure(std::move(other.m_f));
63 }
64 m_success = other.m_success;
65 return *this;
66 }
67
68 TResult const& get_result() const&
69 {
70 assert(m_success);
71 return m_s;
72 }
73
74 TResult&& get_result() &&
75 {
76 assert(m_success);
77 return std::move(m_s);
78 }
79
80 TFailure const& get_failure() const&
81 {

Callers 1

PassedMethod · 0.85

Calls

no outgoing calls

Tested by 1

PassedMethod · 0.68