class maybe
Declaration
template <typename T>
class maybe { /* full declaration omitted */ };
Description
A monadic type that may or may not contain a value.
Declared at: libreglisse/maybe.hpp:143
Member Variables
- private bool m_is_none = true
- private anonymous struct / union
Method Overview
- public constexpr auto borrow() & -> reglisse::maybe::value_type &
- public constexpr auto borrow() const & -> const reglisse::maybe::value_type &
- public constexpr auto is_none() const noexcept -> bool
- public constexpr auto is_some() const noexcept -> bool
- public constexpr maybe<T>(reglisse::none_t) noexcept
- public constexpr maybe<T>(some<T> && val)
- public constexpr maybe<T>(const maybe<T> & other)
- public constexpr maybe<T>(maybe<T> && other) noexcept
- public constexpr maybe<T>() noexcept
- public constexpr bool operator bool() const noexcept
- public constexpr void reset()
- public constexpr void swap(maybe<T> & other)
- public constexpr auto take() && -> reglisse::maybe::value_type
- public constexpr auto take() const && -> reglisse::maybe::value_type
- public template <class U>constexpr auto take_or(U && or_val) && -> reglisse::maybe::value_type
- public template <class U>constexpr auto take_or(U && or_val) const && -> reglisse::maybe::value_type
- public constexpr ~maybe<T>()
Methods
constexpr auto
borrow() & -> reglisse::maybe::value_type&
constexpr auto
borrow() & -> reglisse::maybe::value_type&
Description
Borrow the value stored in the monad.
If the monad does not hold a value, an assert will be thrown at debug time will be thrown. If you wish to have runtime checking, defining the LIBREGLISSE_USE_EXCEPTIONS macro before including this file will turn all assertions into exceptions.
Declared at: libreglisse/maybe.hpp:241
Returns
The value stored in the monad.
constexpr auto borrow()
const& -> const reglisse::maybe::value_type&
constexpr auto borrow()
const& -> const reglisse::maybe::value_type&
Description
Borrow the value stored in the monad.
If the monad does not hold a value, an assert will be thrown at debug time will be thrown. If you wish to have runtime checking, defining the LIBREGLISSE_USE_EXCEPTIONS macro before including this file will turn all assertions into exceptions.
Declared at: libreglisse/maybe.hpp:256
Returns
The value stored in the monad.
constexpr auto is_none() const noexcept -> bool
constexpr auto is_none() const noexcept -> bool
Description
Check if the monad is empty.
Declared at: libreglisse/maybe.hpp:394
Returns
true if monad is empty
constexpr auto is_some() const noexcept -> bool
constexpr auto is_some() const noexcept -> bool
Description
Check if the monad holds some value.
Declared at: libreglisse/maybe.hpp:388
Returns
true if monad is not empty
constexpr maybe<T>(reglisse::none_t) noexcept
constexpr maybe<T>(reglisse::none_t) noexcept
Description
construct an empty monad.
Declared at: libreglisse/maybe.hpp:153
Parameters
constexpr maybe<T>(some<T>&& val)
constexpr maybe<T>(some<T>&& val)
Description
construct monad from some value.
Declared at: libreglisse/maybe.hpp:159
Parameters
- some<T>&& val
- The value to take.
constexpr maybe<T>(const maybe<T>& other)
constexpr maybe<T>(const maybe<T>& other)
Description
Copy construct a maybe.
Declared at: libreglisse/maybe.hpp:163
Parameters
- const maybe<T>& other
constexpr maybe<T>(maybe<T>&& other) noexcept
constexpr maybe<T>(maybe<T>&& other) noexcept
Description
Move construct a maybe.
Declared at: libreglisse/maybe.hpp:173
Parameters
- maybe<T>&& other
constexpr maybe<T>() noexcept
constexpr maybe<T>() noexcept
Declared at: libreglisse/maybe.hpp:149
constexpr bool operator bool() const noexcept
constexpr bool operator bool() const noexcept
Description
Check if the monad holds some value.
Declared at: libreglisse/maybe.hpp:400
Returns
true if monad is not empty
constexpr void reset()
constexpr void reset()
Description
Reset the monad to it's default state
Declared at: libreglisse/maybe.hpp:345
constexpr void swap(maybe<T>& other)
constexpr void swap(maybe<T>& other)
Description
Swap the content with 'other'
Declared at: libreglisse/maybe.hpp:359
Parameters
- maybe<T>& other
- The maybe to swap content with
constexpr auto
take() && -> reglisse::maybe::value_type
constexpr auto
take() && -> reglisse::maybe::value_type
Description
Take the value stored in the monad.
This operation leaves the monad in an undefined state, it is not recommended to use it after this function being called. If the monad does not hold a value, an assert will be thrown at debug time will be thrown. If you wish to have runtime checking, defining the LIBREGLISSE_USE_EXCEPTIONS macro before including this file will turn all assertions into exceptions.
Declared at: libreglisse/maybe.hpp:275
Returns
The value stored in the monad.
constexpr auto take()
const&& -> reglisse::maybe::value_type
constexpr auto take()
const&& -> reglisse::maybe::value_type
Description
Take the value stored in the monad.
This operation leaves the monad in an undefined state, it is not recommended to use it after this function being called. If the monad does not hold a value, an assert will be thrown at debug time will be thrown. If you wish to have runtime checking, defining the LIBREGLISSE_USE_EXCEPTIONS macro before including this file will turn all assertions into exceptions.
Declared at: libreglisse/maybe.hpp:294
Returns
The value stored in the monad.
template <class U>
constexpr auto take_or(
U&& or_val) && -> reglisse::maybe::value_type
template <class U>
constexpr auto take_or(
U&& or_val) && -> reglisse::maybe::value_type
Description
Take the value stored in the monad or get a default.
This operation may leave the monad in an undefined state, it is not recommended to use it after this function being called.
Declared at: libreglisse/maybe.hpp:312
Parameters
- U&& or_val
- The default value to use in case monad is empty
Returns
The value stored in the monad or the provided or_val.
template <class U>
constexpr auto take_or(U&& or_val)
const&& -> reglisse::maybe::value_type
template <class U>
constexpr auto take_or(U&& or_val)
const&& -> reglisse::maybe::value_type
Description
Take the value stored in the monad or get a default.
This operation may leave the monad in an undefined state, it is not recommended to use it after this function being called.
Declared at: libreglisse/maybe.hpp:332
Parameters
- U&& or_val
- The default value to use in case monad is empty
Returns
The value stored in the monad or the provided or_val.
constexpr ~maybe<T>()
constexpr ~maybe<T>()
Description
Destroy maybe.
Declared at: libreglisse/maybe.hpp:183