1 #ifndef EAGINE_SMART_CALLABLE_HPP
9 #define EAGINE_SMART_CALLABLE_HPP
17 template <
bool Asserting,
typename Callable>
20 template <
bool Asserting,
typename RV,
typename... Params>
21 class smart_callable_base;
23 template <
typename RV,
typename... Params>
24 class smart_callable_base<false, RV, Params...> {
26 template <
typename Callable,
typename... Args>
27 static constexpr
auto _invoke(Callable& callable, Args&&... args) {
30 EAGINE_DIAG_OFF(conversion)
31 EAGINE_DIAG_OFF(sign-conversion)
33 using ORV = optionally_valid<RV>;
34 return args_within_limits_of<Params...>(args...)
35 ? ORV{callable(std::forward<Args>(args)...)}
43 template <
typename RV,
typename... Params>
44 class smart_callable_base<true, RV, Params...> {
46 template <
typename Callable,
typename... Args>
47 static constexpr
auto _invoke(Callable& callable, Args&&... args) {
50 EAGINE_DIAG_OFF(conversion)
51 EAGINE_DIAG_OFF(sign-conversion)
53 EAGINE_ASSERT(args_within_limits_of<Params...>(args...));
54 return callable(std::forward<Args>(args)...);
61 template <
bool Asseting,
typename RV,
typename... Params>
62 class smart_callable<Asseting, RV (*)(Params...)>
63 :
public smart_callable_base<Asseting, RV, Params...> {
65 constexpr smart_callable(RV (*
function)(Params...)) noexcept
66 : _function{
function} {}
68 template <
typename... Args>
69 constexpr
auto operator()(Args&&... args)
const {
70 this->_invoke(_function, std::forward<Args>(args)...);
74 RV (*_function)(Params...) =
nullptr;
77 template <
typename RV,
typename... Params>
78 static constexpr smart_callable<
false, RV (*)(Params...)>
79 smart_call(RV (*
function)(Params...)) noexcept {
83 template <
typename RV,
typename... Params>
84 static constexpr smart_callable<
true, RV (*)(Params...)>
85 safe_call(RV (*
function)(Params...)) noexcept {
91 #endif // EAGINE_SMART_CALLABLE_HPP