7 #ifndef ZPP_INCLUDE_ZPP_RESULT_HPP
8 #define ZPP_INCLUDE_ZPP_RESULT_HPP
10 #include <zephyr/kernel.h>
11 #include <zephyr/sys/__assert.h>
24 template<
typename T_Error>
26 static_assert(!std::is_void_v<T_Error>);
27 static_assert(std::is_copy_constructible_v<T_Error>);
28 static_assert(std::is_move_constructible_v<T_Error>);
29 static_assert(std::is_copy_assignable_v<T_Error>);
30 static_assert(std::is_move_assignable_v<T_Error>);
55 : m_error(std::move(rhs))
73 const T_Error&
error() const noexcept {
88 template<
typename T_Ok,
typename T_Error>
90 static_assert(!std::is_void_v<T_Ok>);
91 static_assert(std::is_copy_constructible_v<T_Ok>);
92 static_assert(std::is_move_constructible_v<T_Ok>);
93 static_assert(std::is_copy_assignable_v<T_Ok>);
94 static_assert(std::is_move_assignable_v<T_Ok>);
96 static_assert(!std::is_void_v<T_Error>);
97 static_assert(std::is_copy_constructible_v<T_Error>);
98 static_assert(std::is_move_constructible_v<T_Error>);
99 static_assert(std::is_copy_assignable_v<T_Error>);
100 static_assert(std::is_move_assignable_v<T_Error>);
162 : m_is_ok(rhs.m_is_ok)
177 : m_is_ok(rhs.m_is_ok)
180 new(&
m_ok_value) T_Ok(std::move(rhs.m_ok_value));
342 const T_Ok&
value() const noexcept {
373 const T_Error&
error() const noexcept {
447 constexpr
explicit operator bool() const noexcept {
466 template<
typename T_Error>
468 static_assert(!std::is_void_v<T_Error>);
469 static_assert(std::is_copy_constructible_v<T_Error>);
470 static_assert(std::is_move_constructible_v<T_Error>);
471 static_assert(std::is_copy_assignable_v<T_Error>);
472 static_assert(std::is_move_assignable_v<T_Error>);
614 const T_Error&
error() const noexcept {
636 constexpr
explicit operator bool() const noexcept {
654 template<
typename T_Ok,
typename T_Error>
656 return bool(lhs) == bool(rhs);
667 template<
typename T_Ok,
typename T_Error>
669 return bool(lhs) == bool(rhs);
680 template<
typename T_Ok,
typename T_Error>
682 return bool(lhs) != bool(rhs);
693 template<
typename T_Ok,
typename T_Error>
695 return bool(lhs) != bool(rhs);
helper class for error result
T_Error & error() noexcept
return error value
const T_Error & error() const noexcept
return error value
error_result() noexcept=delete
error_result(T_Error &&rhs) noexcept
initialize error_result
result(const result &rhs) noexcept=default
copy contructor
result() noexcept=default
default initialization to error state
void assign_error(const T_Error &e) noexcept
constexpr bool has_value() const noexcept
convert the result to a bool
const T_Error & error() const noexcept
return a const reference to the result value
result(error_result< T_Error > &&rhs) noexcept
void value() const noexcept
return a const reference to the result value
T_Error & error() noexcept
return a reference to the OK value
void assign_error(T_Error &&e) noexcept
void value() noexcept
return a reference to the OK value
result(result &&rhs) noexcept=default
move contructor
result & operator=(const error_result< T_Error > &rhs) noexcept
copy operator
result & operator=(error_result< T_Error > &&rhs) noexcept
move operator
~result() noexcept=default
destructor
result(const error_result< T_Error > &rhs) noexcept
initialization to error state
T_Ok * operator->() noexcept
return a pointer to the result value
result(result &&rhs) noexcept
move contructor
void assign_value(T_Ok &&v) noexcept
constexpr bool has_value() const noexcept
convert the result to a bool
result() noexcept
default initialization to error state
result(error_result< T_Error > &&rhs) noexcept
initialization to error state
void assign_value(const T_Ok &v) noexcept
const T_Ok * operator->() const noexcept
return a const pointer to the result value
result(T_Ok &&rhs) noexcept
initialization to OK state
T_Ok & value() noexcept
return a reference to the OK value
const T_Error & error() const noexcept
return a const reference to the result value
~result() noexcept
destructor
result & operator=(error_result< T_Error > &&rhs) noexcept
move operator
result & operator=(const result &rhs) noexcept
copy operator
void assign_error(T_Error &&e) noexcept
void assign_error(const T_Error &e) noexcept
result & operator=(T_Ok &&rhs) noexcept
move operator
T_Ok & operator*() noexcept
return a reference to the result value
const T_Ok & value() const noexcept
return a const reference to the result value
result(const T_Ok &rhs) noexcept
initialization to OK state
result & operator=(const T_Ok &rhs) noexcept
copy operator
T_Error & error() noexcept
return a reference to the OK value
const T_Ok & operator*() const noexcept
return a const reference to the result value
result(const result &rhs) noexcept
copy contructor
result & operator=(const error_result< T_Error > &rhs) noexcept
copy operator
result & operator=(result &&rhs) noexcept
move operator
constexpr bool operator==(const result< T_Ok, T_Error > &lhs, bool rhs) noexcept
compare result with bool
constexpr bool operator!=(const result< T_Ok, T_Error > &lhs, bool rhs) noexcept
compare result with bool