Molassembler  3.0.0
Molecule graph and conformer library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Scine::Molassembler::Temple::Optional< T > Class Template Reference

An Option monadic type. More...

#include <Optional.h>

Public Member Functions

Constructors
constexpr Optional ()
 Default constructor. More...
 
constexpr Optional (T value)
 Value constructor.
 
Information
PURITY_WEAK constexpr bool hasValue () const
 Returns whether the optional contains a value. More...
 
PURITY_WEAK constexpr T value () const
 Returns the contained value unchecked. More...
 
template<class UnaryFunction >
constexpr auto map (UnaryFunction &&function) const
 Monadic bind with function of signature T -> U. More...
 
template<class UnaryFunction >
constexpr auto flatMap (UnaryFunction &&function) const
 Monadic bind with function of signature T -> Optional<U> More...
 
PURITY_WEAK constexpr T valueOr (const T &alternative) const
 Returns a value if initialized, and another if not. More...
 
Operators
constexpr Optionaloperator= (T assignment)
 Assignment from T.
 
PURITY_WEAK constexpr operator bool () const
 Convert-to-bool operator.
 
PURITY_WEAK constexpr bool operator== (const Optional &other) const
 Compares on basis of contained value. Nones do compare equal.
 
PURITY_WEAK constexpr bool operator!= (const Optional &other) const
 Compares on basis of contained value. Nones do compare equal.
 
PURITY_WEAK constexpr bool operator< (const Optional &other) const
 Lexicographical-like comparison.
 
PURITY_WEAK constexpr bool operator> (const Optional &other) const
 Lexicographical-like comparison.
 

Private Attributes

value_ = T {}
 
bool hasValue_ = false
 

Detailed Description

template<typename T>
class Scine::Molassembler::Temple::Optional< T >

An Option monadic type.

A constexpr option type much like std::optional with the limitation that T must be:

  • DefaultConstructible
  • LessThanComparable
  • EqualityComparable

(see the C++ standard definitions)

Warning
T may not be a reference or const-qualified type. Those are impossible to implement constexpr in C++14 as far as I can tell.

Constructor & Destructor Documentation

template<typename T >
constexpr Scine::Molassembler::Temple::Optional< T >::Optional ( )
inline

Default constructor.

None value. Default constructs a contained type.

Member Function Documentation

template<typename T >
template<class UnaryFunction >
constexpr auto Scine::Molassembler::Temple::Optional< T >::flatMap ( UnaryFunction &&  function) const
inline

Monadic bind with function of signature T -> Optional<U>

Template Parameters
UnaryFunction,:Function of signature T -> Optional<U>
Returns
Optional<U>
template<typename T >
PURITY_WEAK constexpr bool Scine::Molassembler::Temple::Optional< T >::hasValue ( ) const
inline

Returns whether the optional contains a value.

Complexity \(\Theta(1)\)

template<typename T >
template<class UnaryFunction >
constexpr auto Scine::Molassembler::Temple::Optional< T >::map ( UnaryFunction &&  function) const
inline

Monadic bind with function of signature T -> U.

Template Parameters
UnaryFunction,:Function of signature T -> U
Returns
Optional<U>
template<typename T >
PURITY_WEAK constexpr T Scine::Molassembler::Temple::Optional< T >::value ( ) const
inline

Returns the contained value unchecked.

Complexity \(\Theta(1)\)

Warning
If hasValue is false, this is UB.
template<typename T >
PURITY_WEAK constexpr T Scine::Molassembler::Temple::Optional< T >::valueOr ( const T &  alternative) const
inline

Returns a value if initialized, and another if not.

Complexity \(\Theta(1)\)


The documentation for this class was generated from the following file: