11static_assert(
HX_CPLUSPLUS >= 202302L,
"hxexpected.hpp requires C++23");
14#if HX_USE_MACROS_WITH_MODULE
15#error Header does not provide macros alone.
25concept hxexpected_concept_ =
requires(T_& x_,
const T_& y_) {
37concept hxunexpected_concept_ =
requires(E_& x_,
const E_& y_) {
46 {
static_cast<bool>(y_) };
50template<hxexpected_concept_ T_, hxunexpected_concept_ E_=
bool>
class hxexpected;
54template<
typename>
class hxis_hxexpected_ :
public hxfalse_t { };
55template<
typename T_,
typename E_>
66template<hxexpected_concept_ T_, hxunexpected_concept_ E_>
71 static_assert(!
hxis_pointer<T_>(),
"hxexpected does not support pointer types");
99 template<
typename error_t_=E_,
typename... args_t_, hxenable_if_t<
100 !hxis_hxexpected_<hxremove_cvref_t<error_t_>>
::value,
bool> =
true>
101 explicit hxexpected(error_t_&& error_, args_t_&&... args_)
noexcept;
119 hxattr_nodiscard explicit operator bool(
void)
const {
return !
static_cast<bool>(m_error_); }
135 template<
typename U_=T_, hxenable_if_t<
136 !hxis_hxexpected_<hxremove_cvref_t<U_>>
::value &&
157 template<
typename self_t_,
typename callable_t_>
164 template<
typename... args_t_>
174 template<
typename self_t_>
187 template<
typename self_t_,
typename callable_t_>
196 void reset(
const E_& error_)
noexcept;
204 template<
typename self_t_>
212 template<
typename self_t_,
typename... args_t_>
230template<
typename T_,
typename E_,
typename... args_t_>
238template<
typename T_,
typename E_>
250template<
typename T_,
typename E_>
255 return expected_.
hash();
259#include "detail/hxexpected.inl"
hxallocator(void)
Definition hxallocator.hpp:35
hxexpected<T, E=bool> - Holds either a value of type T or an error of type E.
Definition hxexpected.hpp:67
const T * operator->(void) const
Returns a const pointer to the contained value.
void reset(void) noexcept
Destroys the contained value and assigns a true error.
T & emplace(args_t_ &&... args_) noexcept
Constructs the contained value in place from args, clearing the error.
E_ error_t
error_t - Publishes the error type.
Definition hxexpected.hpp:74
auto error(this self_t_ &&self_) -> decltype(hxforward_like< self_t_ >(hxdeclval< E_ & >()))
Returns a reference to the error with the constness and value category of self.
hxexpected & operator=(const hxexpected &x_) noexcept
Copy assignment.
bool operator==(const T &value_) const
Returns true if this expected value contains a value equal to value.
void reset(const E_ &error_) noexcept
Changes the error.
~hxexpected(void)
Destroys the contained value if non-null.
void swap(hxexpected &x_) noexcept
Exchanges the values and errors with x.
hxhash_t hash(void) const
Returns the hash of the contained value if non-null, otherwise 31u.
hxexpected(error_t_ &&error_, args_t_ &&... args_) noexcept
Constructs an hxexpected with error.
hxexpected(void)
Default constructs an error using E(true).
Definition hxexpected.hpp:80
hxexpected(hxexpected &&x_) noexcept
Move constructor.
bool equal(const hxexpected &x_) const
Returns true if both expected values contain equal values or equal errors.
T value_or(this self_t_ &&self_, args_t_ &&... args_)
Returns the contained value if non-null, otherwise returns a T constructed from args.
T value_t
value_t - Publishes the contained value type.
Definition hxexpected.hpp:77
hxexpected(hxnil_t)
Constructs an error from hxnil using E(true).
Definition hxexpected.hpp:84
hxexpected(const hxexpected &x_) noexcept
Copy constructor.
bool operator==(hxnil_t) const
Returns true if this expected value contains an error.
Definition hxexpected.hpp:147
hxexpected & operator=(hxnil_t)
Assigns a default error using T(true).
Definition hxexpected.hpp:131
auto and_then(this self_t_ &&self_, callable_t_ &&callable_) -> hxremove_cvref_t< decltype(hxforward< callable_t_ >(callable_)(hxforward_like< self_t_ >(hxdeclval< T & >())))>
Returns the result of calling callable with the contained value when there is no error,...
hxexpected or_else(this self_t_ &&self_, callable_t_ &&callable_)
Returns this expected value if non-null, otherwise returns the result of calling callable.
auto value(this self_t_ &&self_) -> decltype(hxforward_like< self_t_ >(hxdeclval< T & >()))
Returns a reference to the contained value with the constness and value category of self.
const T & operator*(void) const
Returns a const reference to the contained value.
bool operator==(const hxexpected &x_) const
Returns true if both expected values contain equal values or equal errors.
Definition hxexpected.hpp:143
hxexpected & operator=(hxexpected &&x_) noexcept
Move assignment.
bool has_value(void) const
Returns true if the expected value contains a value.
Definition hxexpected.hpp:179
bool operator()(const hxexpected< T, E_ > &x_, const hxexpected< T, E_ > &y_) const
Definition hxexpected.hpp:242
hxkey_equal_t<T> - A constexpr callable that returns true if two objects are equivalent.
Definition hxkey.hpp:57
hxhash_t operator()(const hxexpected< T, E_ > &expected_) const
Definition hxexpected.hpp:254
hxkey_hash_t<T> - A callable that returns the xxhash32 of a numeric value cast to 32 bits.
Definition hxkey.hpp:146
hxnil_t - A class that will only convert to a null T pointer or a null hxhandle_t.
Definition hxutility.h:57
hxsame_as - A concept that requires two types to be the same.
Definition hxutility.h:265
Similar to std::allocator.
hxexpected< T > hxmake_expected(const T &value_)
hxmake_expected<T> - Returns an non-null hxexpected<T> constructed by copying value.
Definition hxexpected.hpp:223
User-specializable key-equal, key-less, and key-hash callables.
#define hxinline
hxinline - Force a function to be inlined into its callers.
Definition hxsettings.h:125
#define HX_CPLUSPLUS
HX_CPLUSPLUS - A version of __cplusplus that is defined to 0 when __cplusplus is undefined.
Definition hxsettings.h:31
#define hxattr_nodiscard
hxattr_nodiscard - Indicates the caller should not discard the return value.
Definition hxsettings.h:98
#define hxattr_flatten
hxattr_flatten - Inline every call inside a function's body into it, recursively, regardless of the c...
Definition hxsettings.h:90
constexpr bool hxis_same(void)
hxis_same<A, B> - Implements std::is_same.
Definition hxutility.h:246
constexpr T && hxforward(hxremove_reference_t< T > &&x_)
hxforward - Implements std::forward.
Definition hxutility.h:353
hxremove_cv_t< hxremove_reference_t< T > > hxremove_cvref_t
hxremove_cvref_t<T> - Returns T with const, volatile, and references removed.
Definition hxutility.h:103
T && hxdeclval(void) noexcept
hxdeclval - Implements std::declval.
constexpr bool hxis_reference(void)
hxis_reference<T> - Implements std::is_reference.
Definition hxutility.h:228
constexpr hxremove_reference_t< T > && hxmove(T &&t_)
hxmove - Implements std::move.
Definition hxutility.h:407
constexpr bool hxis_pointer(void)
hxis_pointer<T> - Implements std::is_pointer.
Definition hxutility.h:216
constexpr hxforward_like_t_< like_t_, value_t_ > hxforward_like(value_t_ &value_)
hxforward_like<T> - Returns value with the constness and value category of T.
Definition hxutility.h:387
Provides core macros, memory management and feature detection.
uint32_t hxhash_t
hxhash_t - Unsigned 32-bit hash value. Expect collisions.
Definition libhatchet.h:210
hxfalse_t - Implements std::false_type.
Definition hxutility.h:112
hxtrue_t - Implements std::true_type.
Definition hxutility.h:110