diff --git a/fluent/Continuable.h b/fluent/Continuable.h index 057815c..cbb1814 100644 --- a/fluent/Continuable.h +++ b/fluent/Continuable.h @@ -31,8 +31,10 @@ struct Continuable ForwardFunction _callback_insert; Continuable<_ATy...>() { } - Continuable<_ATy...>(ForwardFunction&& callback_insert) - : _callback_insert(std::forward(callback_insert)) { } + + template + Continuable<_ATy...>(_FTy&& callback_insert) + : _callback_insert(std::forward<_FTy>(callback_insert)) { } template Continuable<_ATy...>& then(_CTy&&) diff --git a/fluent/functional_unwrap.hpp b/fluent/functional_unwrap.hpp index 67b504d..3230ced 100644 --- a/fluent/functional_unwrap.hpp +++ b/fluent/functional_unwrap.hpp @@ -25,6 +25,7 @@ #define _FUNCTIONAL_UNWRAP_HPP_ #include +#include namespace fu { @@ -106,6 +107,20 @@ namespace fu typedef unwrap_function_impl<_RTy(_ATy...)> type; }; + template + struct to_true + : std::true_type { }; + + /// std::true_type if unwrappable + template + static auto test_unwrappable(int) + -> to_true::type::function_type>; + + /// std::false_type if not unwrappable + template + static auto test_unwrappable(long) + -> std::false_type; + } // detail /// Trait to unwrap function parameters of various types: @@ -140,6 +155,11 @@ namespace fu using function_ptr_of_t = typename detail::select_best_unwrap::type::function_ptr; + /// Trait which defines if the given function is unwrappable or not. + template + struct is_unwrappable + : decltype(detail::test_unwrappable(0)) { }; + } // fu #endif // _FUNCTIONAL_UNWRAP_HPP_ diff --git a/test.cpp b/test.cpp index e23df28..6f413b7 100644 --- a/test.cpp +++ b/test.cpp @@ -6,6 +6,8 @@ #include #include #include +#include +#include enum SpellCastResult { @@ -28,9 +30,24 @@ Continuable CastSpell(int id) }); } -int main(int argc, char** argv) +template +void test_unwrap(std::string const& msg) { - auto lam = [=](Callback&& callback) + std::cout << msg << " is unwrappable: " << (fu::is_unwrappable::value ? "true" : "false") << std::endl; +} + +int main(int /*argc*/, char** /*argv*/) +{ + test_unwrap("void()"); + test_unwrap>("std::function"); + test_unwrap>("std::vector"); + + auto voidcontinue = make_continuable([=](Callback<>&& /*callback*/) + { + + }); + + auto lam = [=](Callback&& /*callback*/) { // on success call the callback with SPELL_FAILED_SUCCESS // callback(SPELL_FAILED_SUCCESS);