|
fp
Functional Programming extensions to C++ for ROS projects.
|
Classes | |
| struct | Error |
| Error type used by Result<T> More... | |
| struct | NoDiscard |
| struct | validate_range |
Typedefs | |
| template<typename T , typename E = Error> | |
| using | Result = tl::expected< T, E > |
Enumerations | |
| enum | ErrorCode : int { ErrorCode::UNKNOWN, ErrorCode::CANCELLED, ErrorCode::INVALID_ARGUMENT, ErrorCode::TIMEOUT, ErrorCode::NOT_FOUND, ErrorCode::ALREADY_EXISTS, ErrorCode::PERMISSION_DENIED, ErrorCode::RESOURCE_EXHAUSTED, ErrorCode::FAILED_PRECONDITION, ErrorCode::ABORTED, ErrorCode::OUT_OF_RANGE, ErrorCode::UNIMPLEMENTED, ErrorCode::INTERNAL, ErrorCode::UNAVAILABLE, ErrorCode::DATA_LOSS, ErrorCode::UNAUTHENTICATED, ErrorCode::EXCEPTION } |
| Enum for ErrorCodes inspired by absl::StatusCode. More... | |
Functions | |
| template<typename T > | |
| constexpr std::optional< T > | make_opt (T value) |
| Makes an optional<T> from a T value. More... | |
| template<typename T , typename F > | |
| constexpr auto | mbind (const std::optional< T > &opt, F f) -> decltype(f(opt.value())) |
| Monad optional bind. More... | |
| template<typename T , typename E , typename F , typename Ret = typename std::result_of<F(T)>::type> | |
| constexpr Ret | mbind (const tl::expected< T, E > &exp, F f) |
| Monad tl::expected<T,E> More... | |
| template<typename F , typename Ret = typename std::result_of<F()>::type, typename Exp = tl::expected<Ret, std::exception_ptr>> | |
| Exp | mtry (F f) |
| Monadic try, used to lift a function that throws an exception one that returns an tl::expected<T, std::exception_ptr> More... | |
| template<typename F , typename G > | |
| constexpr auto | mcompose (F f, G g) |
| Monadic compose two monad functions. More... | |
| template<typename T , typename G , typename... Types> | |
| constexpr auto | mcompose (T t, G g, Types... vars) |
| Variadic mcompose. More... | |
| constexpr std::string_view | toStringView (const ErrorCode &code) |
| convert ErrorCode to string_view for easy formatting More... | |
| template<typename T , typename E = Error> | |
| constexpr Result< T, E > | make_result (T value) |
| Makes a Result<T> from a T value. More... | |
| template<typename T , typename E > | |
| constexpr bool | has_error (const tl::expected< T, E > &exp) |
| Filter function for testing if a result has an error. More... | |
| template<typename E , typename... Args> | |
| constexpr std::optional< E > | maybe_error (tl::expected< Args, E >... args) |
| template<typename F , typename Ret = typename std::result_of<F()>::type, typename Exp = Result<Ret>> | |
| Exp | try_to_result (F f) |
| Try to Result<T>. Lifts a function that throws an excpetpion to one that returns a Result<T> More... | |
| template<typename Rng , typename T > | |
| constexpr Result< T > | validate_in (Rng const &valid_values, T const &value, std::string const &name) |
Variables | |
| constexpr auto | Unknown |
| constexpr auto | Cancelled |
| constexpr auto | InvalidArgument |
| constexpr auto | Timeout |
| constexpr auto | NotFound |
| constexpr auto | AlreadyExists |
| constexpr auto | PermissionDenied |
| constexpr auto | ResourceExhausted |
| constexpr auto | FailedPrecondition |
| constexpr auto | Aborted |
| constexpr auto | OutOfRange |
| constexpr auto | Unimplemented |
| constexpr auto | Internal |
| constexpr auto | Unavailable |
| constexpr auto | DataLoss |
| constexpr auto | Unauthenticated |
| constexpr auto | Exception |
| using fp::Result = typedef tl::expected<T, E> |
Definition at line 187 of file result.hpp.
|
strong |
Enum for ErrorCodes inspired by absl::StatusCode.
Definition at line 48 of file result.hpp.
|
constexpr |
Filter function for testing if a result has an error.
| exp | The expected type to test |
| T | The value type |
| E | The error type |
Definition at line 212 of file result.hpp.
|
constexpr |
|
constexpr |
Makes a Result<T> from a T value.
| [in] | value | The value |
| T | The type of value |
Definition at line 199 of file result.hpp.
|
constexpr |
Definition at line 227 of file result.hpp.
|
constexpr |
|
constexpr |
|
constexpr |
|
constexpr |
Variadic mcompose.
| [in] | t | The first function |
| [in] | g | The second function |
| [in] | vars | The rest of the functions |
| T | The type of the first function |
| G | The type of the second function |
| Types | The types of the rest of the functions |
| Exp fp::mtry | ( | F | f | ) |
Monadic try, used to lift a function that throws an exception one that returns an tl::expected<T, std::exception_ptr>
| [in] | f | The function to call |
| F | The function type |
| Ret | The return value of the function |
| Exp | The expected type |
|
constexpr |
convert ErrorCode to string_view for easy formatting
| [in] | code | The error code |
Definition at line 140 of file result.hpp.
| Exp fp::try_to_result | ( | F | f | ) |
Try to Result<T>. Lifts a function that throws an excpetpion to one that returns a Result<T>
| [in] | f | The function to call |
| F | The function type |
| Ret | The return value of the function |
| Exp | The expected type |
Definition at line 252 of file result.hpp.
|
constexpr |
Definition at line 95 of file validate.hpp.
|
constexpr |
Definition at line 110 of file result.hpp.
|
constexpr |
Definition at line 98 of file result.hpp.
|
constexpr |
Definition at line 86 of file result.hpp.
|
constexpr |
Definition at line 125 of file result.hpp.
|
constexpr |
Definition at line 131 of file result.hpp.
|
constexpr |
Definition at line 107 of file result.hpp.
|
constexpr |
Definition at line 119 of file result.hpp.
|
constexpr |
Definition at line 89 of file result.hpp.
|
constexpr |
Definition at line 95 of file result.hpp.
|
constexpr |
Definition at line 113 of file result.hpp.
|
constexpr |
Definition at line 101 of file result.hpp.
|
constexpr |
Definition at line 104 of file result.hpp.
|
constexpr |
Definition at line 92 of file result.hpp.
|
constexpr |
Definition at line 128 of file result.hpp.
|
constexpr |
Definition at line 122 of file result.hpp.
|
constexpr |
Definition at line 116 of file result.hpp.
|
constexpr |
Definition at line 83 of file result.hpp.