13#if HX_USE_MACROS_WITH_MODULE
14#error Header does not provide macros alone.
28template<
typename>
struct hxis_hxoptional_ : hxfalse_t { };
29template<
typename U_>
struct hxis_hxoptional_<hxoptional<U_>> : hxtrue_t { };
93 template<
typename U_=T_, hxenable_if_t<
94 !hxdetail_::hxis_hxoptional_<hxremove_cvref_t<U_>>
::value,
bool> =
true>
133 template<
typename U_=T_, hxenable_if_t<
134 !hxdetail_::hxis_hxoptional_<hxremove_cvref_t<U_>>
::value,
bool> =
true>
140 template<
typename U_>
146 template<
typename U_>
162#if HX_CPLUSPLUS < 202002L
165 hxattr_nodiscard bool operator!=(const hxoptional& rhs_) const { return !(*this == rhs_); }
174 hxattr_nodiscard bool operator!=(
const T_& value_)
const {
return !(*
this == value_); }
181 template<
typename function_t_>
189 template<
typename function_t_>
196 template<
typename... args_t_>
205 template<
typename function_t_>
228 template<
typename U_=T_>
232 alignas(T_)
char m_storage_[
sizeof(T_)];
247template<
typename T_,
typename... args_t_>
262#include "detail/hxoptional.inl"
hxoptional<T> - Holds either a value of type T or nothing.
Definition hxoptional.hpp:52
const T & operator*(void) const
Returns a const reference to the contained value.
hxoptional or_else(function_t_ &&callable_) const
Returns a copy of this optional if engaged, otherwise returns the result of calling callable.
hxoptional(const hxoptional< U_ > &other_) noexcept
Constructs by copying the engaged state and converting the value of other to T.
hxoptional & operator=(const hxoptional< U_ > &other_) noexcept
Copies the engaged state and converts the value of other to T.
bool has_value(void) const
Returns true if the optional contains a value.
Definition hxoptional.hpp:200
T value_or(U_ &&default_value_) const
Returns the contained value if engaged, otherwise returns default_value forwarded and converted to T.
T & operator*(void)
Returns a reference to the contained value.
T * operator->(void)
Returns a pointer to the contained value. The optional must be engaged.
hxoptional(void)
Constructs a disengaged hxoptional.
Definition hxoptional.hpp:63
hxoptional & operator=(hxoptional< U_ > &&other_) noexcept
Moves the engaged state and converts the value of other to T.
hxoptional(const hxoptional &other_) noexcept
Copy constructor.
bool operator==(const T &value_) const
Returns true if this optional is engaged and its value equals value.
void reset(void) noexcept
Destroys the contained value if engaged and leaves the optional disengaged.
T & emplace(args_t_ &&... args_) noexcept
Constructs the contained value in place from args, destroying any previous value.
hxoptional(hxoptional< U_ > &&other_) noexcept
Constructs by moving the engaged state and converting the value of other to T.
auto and_then(function_t_ &&callable_) -> hxremove_cvref_t< decltype(hxforward< function_t_ >(callable_)(hxdeclval< T & >()))>
Returns the result of calling callable with the contained value if engaged, otherwise returns a disen...
T value_type
value_type - Publishes the contained value type.
Definition hxoptional.hpp:60
const T * operator->(void) const
Returns a const pointer to the contained value.
hxoptional & operator=(U_ &&value_) noexcept
Assigns value by forwarding, engaging the optional.
T & value(void)
Returns a reference to the contained value.
~hxoptional(void)
Destroys the contained value if engaged.
Definition hxoptional.hpp:98
hxoptional(U_ &&value_) noexcept
Constructs an engaged hxoptional by forwarding value into storage.
bool operator==(const hxoptional &rhs_) const
Returns true if both optionals are disengaged or both are engaged with equal values.
hxoptional & operator=(const hxoptional &other_) noexcept
Copy assignment.
hxoptional & operator=(hxoptional &&other_) noexcept
Move assignment.
auto and_then(function_t_ &&callable_) const -> hxremove_cvref_t< decltype(hxforward< function_t_ >(callable_)(hxdeclval< const T & >()))>
Returns the result of calling callable with the contained value if engaged, otherwise returns a disen...
const T & value(void) const
Returns a const reference to the contained value.
hxoptional & operator=(hxnullopt_t)
Disengages the optional, destroying any contained value.
Definition hxoptional.hpp:129
hxoptional(hxoptional &&other_) noexcept
Move constructor.
hxoptional(hxnullopt_t)
Constructs a disengaged hxoptional from hxnullopt.
Definition hxoptional.hpp:67
void swap(hxoptional &other_) noexcept
Exchanges the contents with other.
bool operator==(hxnullopt_t) const
Returns true if this optional is disengaged.
Definition hxoptional.hpp:156
User-overloadable key-equal, key-less, and key-hash functions.
constexpr hxnullopt_t hxnullopt
hxnullopt - A sentinel value of type hxnullopt_t representing a disengaged hxoptional.
Definition hxoptional.hpp:43
hxhash_t hxkey_hash(const hxoptional< T > &opt_)
hxkey_hash(hxoptional<T>) - Returns the hash of the contained value if engaged, otherwise 1u.
Definition hxoptional.hpp:258
hxoptional< hxremove_cvref_t< T > > hxmake_optional(T &&value_)
hxmake_optional - Returns an engaged hxoptional<hxremove_cvref_t<T>> constructed by forwarding value.
Definition hxoptional.hpp:240
#define hxinline_constexpr
hxinline_constexpr - Enables C++17 compatable "inline constexpr" usage for variables so they can be e...
Definition hxsettings.h:272
#define hxattr_nodiscard
hxattr_nodiscard - Indicates the caller should not discard the return value.
Definition hxsettings.h:89
A few utility functions and most standard C++ meta programming functions.
constexpr T && hxforward(hxremove_reference_t< T > &&x_)
hxforward - Implements std::forward.
Definition hxutility.h:304
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:115
T && hxdeclval(void) noexcept
hxdeclval - Implements std::declval.
Provides core macros, memory management and feature detection.
uint32_t hxhash_t
hxhash_t - Unsigned 32-bit hash value. Expect collisions.
Definition libhatchet.h:212
static constexpr bool value
Definition hxutility.h:124
hxis_pointer - Returns whether T is a pointer type as hxis_pointer<T>::value.
Definition hxutility.h:206
hxnullopt_t - A tag type used to construct a disengaged hxoptional.
Definition hxoptional.hpp:34
constexpr hxnullopt_t(int)
Explicit constructor prevents implicit construction from { }.
Definition hxoptional.hpp:37