Created
February 5, 2018 17:02
-
-
Save eguiraud/08a96c13e4440967b56c04cc98d81d28 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ROOT/TypeTraits.hxx> | |
#include <cassert> | |
#include <functional> | |
namespace ROOT { | |
namespace Internal { | |
template <typename... ArgTypes, typename F> | |
std::function<bool(ArgTypes...)> NotHelper(ROOT::TypeTraits::TypeList<ArgTypes...>, F &&f) | |
{ | |
return std::function<bool(ArgTypes...)>([&](ArgTypes... args) { return !f(args...); }); | |
} | |
} // namespace Internal | |
namespace Experimental { | |
namespace TDF { | |
template <typename F, typename Args = typename ROOT::TypeTraits::CallableTraits<typename std::decay<F>::type>::arg_types_nodecay, | |
typename Ret = typename ROOT::TypeTraits::CallableTraits<typename std::decay<F>::type>::ret_type> | |
auto Not(F &&f) -> decltype(ROOT::Internal::NotHelper(Args(), std::forward<F>(f))) | |
{ | |
static_assert(std::is_same<Ret, bool>::value, "TDF::Not requires a callable that returns a bool."); | |
return ROOT::Internal::NotHelper(Args(), std::move(f)); | |
} | |
} // namespace TDF | |
} // namespace Experimental | |
} // namespace ROOT | |
using namespace ROOT::Experimental; | |
int main() | |
{ | |
auto isPos = [](int a) { return a > 0; }; | |
assert(TDF::Not(isPos)(-1) == true); | |
auto isNeg = TDF::Not(isPos); | |
assert(!isNeg(3)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
uhm, spelling the issue was helpful. The jitted case is actually perhaps simpler.
becomes