Logo ROOT   6.14/05
Reference Guide
RDFHelpers.hxx
Go to the documentation of this file.
1 // Author: Enrico Guiraud, Danilo Piparo CERN 02/2018
2 
3 /*************************************************************************
4  * Copyright (C) 1995-2018, Rene Brun and Fons Rademakers. *
5  * All rights reserved. *
6  * *
7  * For the licensing terms see $ROOTSYS/LICENSE. *
8  * For the list of contributors see $ROOTSYS/README/CREDITS. *
9  *************************************************************************/
10 
11 // This header contains helper free functions that slim down RDataFrame's programming model
12 
13 #ifndef ROOT_RDF_HELPERS
14 #define ROOT_RDF_HELPERS
15 
16 #include <ROOT/TypeTraits.hxx>
17 
18 #include <algorithm> // std::transform
19 #include <functional>
20 #include <iterator> // std::back_inserter
21 #include <stdexcept>
22 #include <string>
23 #include <type_traits>
24 #include <vector>
25 
26 namespace ROOT {
27 namespace Internal {
28 template <typename... ArgTypes, typename F>
30 {
31  return std::function<bool(ArgTypes...)>([=](ArgTypes... args) mutable { return !f(args...); });
32 }
33 
34 template <typename... ArgTypes, typename Ret, typename... Args>
36 {
37  return std::function<bool(ArgTypes...)>([=](ArgTypes... args) mutable { return !f(args...); });
38 }
39 } // namespace Internal
40 
41 
42 namespace RDF {
43 // clag-format off
44 /// Given a callable with signature bool(T1, T2, ...) return a callable with same signature that returns the negated
45 /// result
46 ///
47 /// The callable must have one single non-template definition of operator(). This is a limitation with respect to
48 /// std::not_fn, required for interoperability with RDataFrame.
49 // clang-format on
50 template <typename F,
51  typename Args = typename ROOT::TypeTraits::CallableTraits<typename std::decay<F>::type>::arg_types_nodecay,
52  typename Ret = typename ROOT::TypeTraits::CallableTraits<typename std::decay<F>::type>::ret_type>
53 auto Not(F &&f) -> decltype(ROOT::Internal::NotHelper(Args(), std::forward<F>(f)))
54 {
55  static_assert(std::is_same<Ret, bool>::value, "RDF::Not requires a callable that returns a bool.");
56  return ROOT::Internal::NotHelper(Args(), std::forward<F>(f));
57 }
58 
59 } // namespace RDF
60 
61 } // namespace ROOT
62 #endif
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
auto Not(F &&f) -> decltype(ROOT::Internal::NotHelper(Args(), std::forward< F >(f)))
Given a callable with signature bool(T1, T2, ...) return a callable with same signature that returns ...
Definition: RDFHelpers.hxx:53
#define f(i)
Definition: RSha256.hxx:104
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition: RExports.h:146
#define F(x, y, z)
Lightweight storage for a collection of types.
Definition: TypeTraits.hxx:27
std::function< bool(ArgTypes...)> NotHelper(ROOT::TypeTraits::TypeList< ArgTypes... >, F &&f)
Definition: RDFHelpers.hxx:29
Extract types from the signature of a callable object. See CallableTraits.
Definition: TypeTraits.hxx:38