13class Option :
public std::optional<T> {
15 template<
typename... Args>
16 Option(Args&&... args) :
std::optional<T>(
std::forward<Args>(args)...) {}
25 const T &
value_or_throw(
const std::string& message=
"No value present!") const& {
26 if (this->has_value())
28 throw std::runtime_error(message);
39 if (this->has_value())
40 return std::move(this->value());
41 throw std::runtime_error(message);
53 using U =
typename std::remove_cvref_t<std::invoke_result_t<F, const T&>>::value_type;
54 if (this->has_value())
55 return std::invoke(std::forward<F>(f), this->value());
68 using U =
typename std::remove_cvref_t<std::invoke_result_t<F, T>>::value_type;
69 if (this->has_value())
70 return std::invoke(std::forward<F>(f), std::move(this->value()));
83 using U = std::remove_cvref_t<std::invoke_result_t<F, const T&>>;
84 if (this->has_value())
85 return Option<U>(std::invoke(std::forward<F>(f), this->value()));
98 using U = std::remove_cvref_t<std::invoke_result_t<F, T>>;
99 if (this->has_value())
100 return Option<U>(std::invoke(std::forward<F>(f), std::move(this->value())));
111 template<
typename F>
requires std::convertible_to<std::invoke_result_t<F>,T>
113 if (this->has_value())
return *
this;
114 return std::invoke(std::forward<F>(f));
124 template<
typename F>
requires std::convertible_to<std::invoke_result_t<F>,
Option<T>>
126 if (this->has_value())
return std::move(*
this);
127 return std::invoke(std::forward<F>(f));
137 if (this->has_value() && predicate(this->value()))
149 if (this->has_value())
150 consumer(std::forward<T>(this->value()));
161 if (this->has_value())
162 consumer(std::forward<T>(this->value()));
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 fu...
Definition Option.hpp:160
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.
Definition Option.hpp:52
Option< T > or_else(F &&f) const &
If the Option has a value, return it. Otherwise, call the provided function and return its result.
Definition Option.hpp:112
Option< T > or_else(F &&f) &&
If the Option has a value, return it. Otherwise, call the provided function and return its result.
Definition Option.hpp:125
Option(Args &&... args)
Definition Option.hpp:16
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.
Definition Option.hpp:148
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.
Definition Option.hpp:82
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...
Definition Option.hpp:38
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,...
Definition Option.hpp:136
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.
Definition Option.hpp:67
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.
Definition Option.hpp:97
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...
Definition Option.hpp:25
Definition FunctionalConcepts.hpp:54
Definition FunctionalConcepts.hpp:36
Definition FunctionalConcepts.hpp:60
Definition FunctionalConcepts.hpp:9
Definition BFSClustering.hpp:5