pstore2
Classes | Typedefs | Functions
maybe.hpp File Reference

An implementation of the Haskell Maybe type. More...

#include <new>
#include <stdexcept>
#include "pstore/adt/utility.hpp"
#include "pstore/support/assert.hpp"
#include "pstore/support/inherit_const.hpp"
Include dependency graph for maybe.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  pstore::details::remove_cvref< T >
 
class  pstore::maybe< T, typename >
 

Typedefs

template<typename T >
using pstore::details::remove_cvref_t = typename remove_cvref< T >::type
 

Functions

template<typename T >
decltype(auto) constexpr pstore::just (T &&value)
 
template<typename T , typename... Args>
decltype(auto) constexpr pstore::just (in_place_t const inp, Args &&... args)
 
template<typename T >
decltype(auto) constexpr pstore::nothing () noexcept
 
template<typename T , typename Function >
auto pstore::operator>>= (maybe< T > &&t, Function f) -> decltype(f(*t))
 The monadic "bind" operator for maybe<T>. More...
 

Detailed Description

An implementation of the Haskell Maybe type.

In Haskell, this simply looks like: data Maybe a = Just a | Nothing This is pretty much std::optional<> and this definition deliberately implements some of the methods of that type, so we should switch to the standard type once we're able to migrate to C++17.

Function Documentation

◆ operator>>=()

template<typename T , typename Function >
auto pstore::operator>>= ( maybe< T > &&  t,
Function  f 
) -> decltype (f (*t))

The monadic "bind" operator for maybe<T>.

If t is "nothing", then returns nothing where the type of the return is derived from the return type of f. If t has a value then returns the result of calling f.

Template Parameters
TThe input type wrapped by a maybe<>.
FunctionA callable object whose signature is of the form maybe<U> f(T t).