Fishnet 2.0.1
Framework for Graph-Based Analysis of GIS Vector Data
Loading...
Searching...
No Matches
fishnet::Option< T > Class Template Reference

#include <Option.hpp>

Inheritance diagram for fishnet::Option< T >:
Collaboration diagram for fishnet::Option< T >:

Public Member Functions

template<typename... Args>
 Option (Args &&... args)
 
const T & value_or_throw (const std::string &message="No value present!") const &
 Get the value of the Option if it has a value, otherwise throw an exception with the provided message.
 
T && value_or_throw (const std::string &message="No value present!") &&
 Get the value of the Option if it has a value, otherwise throw an exception with the provided message.
 
template<typename F >
requires fishnet::util::UnaryFunction<F,T,Option<typename std::remove_cvref_t<std::invoke_result_t<F,T>>::value_type>>
Option< typename std::remove_cvref_t< std::invoke_result_t< F, T > >::value_type > and_then (F &&f) const &
 FlatMap the value of the Option if it has a value, otherwise return an empty Option.
 
template<typename F >
requires fishnet::util::UnaryFunction<F,T,Option<typename std::remove_cvref_t<std::invoke_result_t<F,T>>::value_type>>
Option< typename std::remove_cvref_t< std::invoke_result_t< F, T > >::value_type > and_then (F &&f) &&
 FlatMap the value of the Option if it has a value, otherwise return an empty Option.
 
template<typename F >
requires fishnet::util::UnaryFunction<F,T,typename std::remove_cvref_t<std::invoke_result_t<F,T>>>
Option< typename std::remove_cvref_t< std::invoke_result_t< F, T > > > transform (F &&f) const &
 Transform the value of the Option if it has a value, otherwise return an empty Option.
 
template<typename F >
requires fishnet::util::UnaryFunction<F,T,typename std::remove_cvref_t<std::invoke_result_t<F,T>>>
Option< typename std::remove_cvref_t< std::invoke_result_t< F, T > > > transform (F &&f) &&
 Transform the value of the Option if it has a value, otherwise return an empty Option.
 
template<typename F >
requires std::convertible_to<std::invoke_result_t<F>,T>
Option< T > or_else (F &&f) const &
 If the Option has a value, return it. Otherwise, call the provided function and return its result.
 
template<typename F >
requires std::convertible_to<std::invoke_result_t<F>,Option<T>>
Option< T > or_else (F &&f) &&
 If the Option has a value, return it. Otherwise, call the provided function and return its result.
 
Option< T > filter (fishnet::util::Predicate< T > auto const &predicate)
 If the Option has a value and the predicate returns true, return the Option. Otherwise, return an empty Option.
 
void if_value (fishnet::util::Consumer< T > auto const &consumer)
 If the Option has a value, call the provided function with the value. Otherwise, do nothing.
 
void if_value_or_else (fishnet::util::Consumer< T > auto const &consumer, fishnet::util::Runnable auto const &runnable)
 If the Option has a value, call the provided function with the value. Otherwise, call the provided function.
 

Constructor & Destructor Documentation

◆ Option()

template<typename T >
template<typename... Args>
fishnet::Option< T >::Option ( Args &&...  args)
inline

Member Function Documentation

◆ and_then() [1/2]

template<typename T >
template<typename F >
requires fishnet::util::UnaryFunction<F,T,Option<typename std::remove_cvref_t<std::invoke_result_t<F,T>>::value_type>>
Option< typename std::remove_cvref_t< std::invoke_result_t< F, T > >::value_type > fishnet::Option< T >::and_then ( F &&  f) &&
inline

FlatMap the value of the Option if it has a value, otherwise return an empty Option.

Template Parameters
F(T&&) -> Option
Parameters
fflatMap function
Returns
Option &&

◆ and_then() [2/2]

template<typename T >
template<typename F >
requires fishnet::util::UnaryFunction<F,T,Option<typename std::remove_cvref_t<std::invoke_result_t<F,T>>::value_type>>
Option< typename std::remove_cvref_t< std::invoke_result_t< F, T > >::value_type > fishnet::Option< T >::and_then ( F &&  f) const &
inline

FlatMap the value of the Option if it has a value, otherwise return an empty Option.

Template Parameters
F(T) -> Option
Parameters
fflatMap function
Returns
Option

◆ filter()

template<typename T >
Option< T > fishnet::Option< T >::filter ( fishnet::util::Predicate< T > auto const &  predicate)
inline

If the Option has a value and the predicate returns true, return the Option. Otherwise, return an empty Option.

Parameters
predicate(T) -> bool
Returns
Option<T>

◆ if_value()

template<typename T >
void fishnet::Option< T >::if_value ( fishnet::util::Consumer< T > auto const &  consumer)
inline

If the Option has a value, call the provided function with the value. Otherwise, do nothing.

Parameters
consumer(T) -> void
Returns
void

◆ if_value_or_else()

template<typename T >
void fishnet::Option< T >::if_value_or_else ( fishnet::util::Consumer< T > auto const &  consumer,
fishnet::util::Runnable auto const &  runnable 
)
inline

If the Option has a value, call the provided function with the value. Otherwise, call the provided function.

Parameters
consumer(T) -> void
runnable() -> void
Returns
void

◆ or_else() [1/2]

template<typename T >
template<typename F >
requires std::convertible_to<std::invoke_result_t<F>,Option<T>>
Option< T > fishnet::Option< T >::or_else ( F &&  f) &&
inline

If the Option has a value, return it. Otherwise, call the provided function and return its result.

Template Parameters
F() -> T
Parameters
ffunction to call if the Option is empty
Returns
Option<T> &&

◆ or_else() [2/2]

template<typename T >
template<typename F >
requires std::convertible_to<std::invoke_result_t<F>,T>
Option< T > fishnet::Option< T >::or_else ( F &&  f) const &
inline

If the Option has a value, return it. Otherwise, call the provided function and return its result.

Template Parameters
F() -> T
Parameters
ffunction to call if the Option is empty
Returns
Option<T>

◆ transform() [1/2]

template<typename T >
template<typename F >
requires fishnet::util::UnaryFunction<F,T,typename std::remove_cvref_t<std::invoke_result_t<F,T>>>
Option< typename std::remove_cvref_t< std::invoke_result_t< F, T > > > fishnet::Option< T >::transform ( F &&  f) &&
inline

Transform the value of the Option if it has a value, otherwise return an empty Option.

Template Parameters
F(T&&) -> U
Parameters
fmap function
Returns
Option &&

◆ transform() [2/2]

template<typename T >
template<typename F >
requires fishnet::util::UnaryFunction<F,T,typename std::remove_cvref_t<std::invoke_result_t<F,T>>>
Option< typename std::remove_cvref_t< std::invoke_result_t< F, T > > > fishnet::Option< T >::transform ( F &&  f) const &
inline

Transform the value of the Option if it has a value, otherwise return an empty Option.

Template Parameters
F(T) -> U
Parameters
fmap function
Returns
Option

◆ value_or_throw() [1/2]

template<typename T >
T && fishnet::Option< T >::value_or_throw ( const std::string &  message = "No value present!") &&
inline

Get the value of the Option if it has a value, otherwise throw an exception with the provided message.

Parameters
messageThe message to include in the exception if the Option is empty.
Returns
T&& The value of the Option.
Exceptions
std::runtime_errorif the Option is empty.

◆ value_or_throw() [2/2]

template<typename T >
const T & fishnet::Option< T >::value_or_throw ( const std::string &  message = "No value present!") const &
inline

Get the value of the Option if it has a value, otherwise throw an exception with the provided message.

Parameters
messageThe message to include in the exception if the Option is empty.
Returns
const T& The value of the Option.
Exceptions
std::runtime_errorif the Option is empty.

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