![]() |
|
Include dependency graph for tryInvoke.h:
This graph shows which files directly or indirectly include this file:Go to the source code of this file.
Functions | |
| template<class Ret > | |
| constexpr auto | TfNotInvoked () |
Return the result type of TfTryInvoke<Ret> in the case where the function was not invoked – false if Ret is void, otherwise an empty std::optional<Ret>. | |
| template<class Ret , class Fn , class... Args> | |
| auto | TfTryInvoke (Fn &&fn, Args &&...args) |
Invoke fn with args if fn is invocable with those arguments and return a result that indicates both whether the call was made and, if so, what it returned. | |
|
constexpr |
Return the result type of TfTryInvoke<Ret> in the case where the function was not invoked – false if Ret is void, otherwise an empty std::optional<Ret>.
Call this when you need to produce the same result type as TfTryInvoke in a context where the function was not called.
Definition at line 26 of file tryInvoke.h.
| auto TfTryInvoke | ( | Fn && | fn, |
| Args &&... | args | ||
| ) |
Invoke fn with args if fn is invocable with those arguments and return a result that indicates both whether the call was made and, if so, what it returned.
The template parameter Ret specifies the expected return type of fn:
fn is invocable and Ret is non-void, invoke fn and return std::optional<Ret> containing the result.fn is invocable and Ret is void, invoke fn and return true.fn is not invocable with args, return TfNotInvoked<Ret>() – an empty std::optional<Ret> or false.The return value is always truthy if fn was invoked and falsy if it was not, regardless of whether Ret is void.
Use this to build operations over heterogeneous collections where a callable may only handle a subset of element types:
Definition at line 68 of file tryInvoke.h.