diff --git a/include/fit/conditional.hpp b/include/fit/conditional.hpp index 67847de..42896e2 100644 --- a/include/fit/conditional.hpp +++ b/include/fit/conditional.hpp @@ -90,6 +90,14 @@ struct conditional_kernel : F1, F2 constexpr conditional_kernel(A&& f1, B&& f2) : F1(FIT_FORWARD(A)(f1)), F2(FIT_FORWARD(B)(f2)) {} + template::type> + constexpr conditional_kernel(X&& x) : F1(FIT_FORWARD(X)(x)) + {} + template struct select : std::conditional @@ -100,18 +108,15 @@ struct conditional_kernel : F1, F2 > {}; - template - constexpr const typename select::type& select_function() const - { - return *this; - } - FIT_RETURNS_CLASS(conditional_kernel); - template + template::type> constexpr FIT_SFINAE_RESULT(typename select::type, id_...) operator()(Ts && ... x) const - FIT_SFINAE_RETURNS(FIT_CONST_THIS->select_function()(FIT_FORWARD(Ts)(x)...)); + FIT_SFINAE_RETURNS + ( + FIT_RETURNS_STATIC_CAST(const F&)(*FIT_CONST_THIS)(FIT_FORWARD(Ts)(x)...) + ); }; } @@ -154,6 +159,19 @@ struct conditional_adaptor : F {}; }; +template +struct conditional_adaptor +: detail::conditional_kernel +{ + typedef detail::conditional_kernel base; + typedef conditional_adaptor fit_rewritable_tag; + FIT_INHERIT_CONSTRUCTOR(conditional_adaptor, base); + + struct failure + : failure_for + {}; +}; + FIT_DECLARE_STATIC_VAR(conditional, detail::make); } // namespace fit