Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
8a7c93a
[TypeTraits] Create TypeTraits namespace
eguiraud Jun 8, 2017
bc08f41
[TypeTraits] Move TDF general-purpose utilities to TTypeTraits.hxx
eguiraud Jun 8, 2017
6f84b40
[TypeTraits] Static-assert that type passed to IsV7Histo is an histogram
eguiraud Jun 9, 2017
d9a0797
[TypeTraits] Add forward declarations for IsV7Hist
eguiraud Jun 9, 2017
d2d2e99
[TypeTraits] Move back IsV7Histo to TDataFrame
eguiraud Jun 13, 2017
c069b65
[TypeTraits] Rename TTypeTraits.hxx -> TypeTraits.hxx
eguiraud Jun 9, 2017
1dc11d9
[TypeTraits] Add missing includes to TypeTraits.hxx
eguiraud Jun 9, 2017
4be3969
[TypeTraits] clang-format TypeTraits.hxx
eguiraud Jun 12, 2017
50d1b36
[TypeTraits] Update `Author` field
eguiraud Jun 12, 2017
a1f1902
[TypeTraits] Add testTypeTraits google test
eguiraud Jun 12, 2017
3c530fa
[TypeTraits] Rename TakeFirst[_t] -> TakeFirstType[_t]
eguiraud Jun 13, 2017
ca17ca6
[TDF] Update TDFActionHelpers.hxx to use ROOT/TypeTraits.hxx
eguiraud Jun 9, 2017
8dd1bb9
[TDF] Update TDFInterface.hxx to use ROOT/TypeTraits.hxx
eguiraud Jun 9, 2017
9a87e70
[TDF] Update TDFNodes.hxx to use ROOT/TypeTraits.hxx
eguiraud Jun 9, 2017
3aa4afa
[TDF] Update TDFUtils.hxx to use ROOT/TypeTraits.hxx
eguiraud Jun 9, 2017
172888b
[TDF] Update TDataFrame.hxx to use ROOT/TypeTraits.hxx
eguiraud Jun 9, 2017
09ebc02
[TDF] Update TResultProxy.hxx to use ROOT/TypeTraits.hxx
eguiraud Jun 9, 2017
1d1ccdd
[TDF] Add helper alias for GenStaticSeq
eguiraud Jun 12, 2017
5dda3b9
[TDF] clang-format pass on TDF headers
eguiraud Jun 12, 2017
24b2b18
[TDF] Fix GenStaticSeq namespace
eguiraud Jun 14, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[TypeTraits] Move TDF general-purpose utilities to TTypeTraits.hxx
  • Loading branch information
eguiraud committed Jun 26, 2017
commit bc08f41659308bcca304d0c83fcc0b41953f418c
132 changes: 132 additions & 0 deletions core/foundation/inc/ROOT/TTypeTraits.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <type_traits>

namespace ROOT{
/// ROOT type_traits extensions
namespace TypeTraits {

///\class ROOT::TypeTraits::
Expand All @@ -27,6 +28,137 @@ class IsSmartOrDumbPtr<std::shared_ptr<P>>: public std::true_type {};
template <class P>
class IsSmartOrDumbPtr<std::unique_ptr<P>>: public std::true_type {};

/// Check for container traits.
template <typename T>
struct IsContainer {
using Test_t = typename std::decay<T>::type;

template <typename A>
static constexpr bool Test(A *pt, A const *cpt = nullptr, decltype(pt->begin()) * = nullptr,
decltype(pt->end()) * = nullptr, decltype(cpt->begin()) * = nullptr,
decltype(cpt->end()) * = nullptr, typename A::iterator *pi = nullptr,
typename A::const_iterator *pci = nullptr)
{
using It_t = typename A::iterator;
using CIt_t = typename A::const_iterator;
using V_t = typename A::value_type;
return std::is_same<Test_t, std::vector<bool>>::value ||
(std::is_same<decltype(pt->begin()), It_t>::value && std::is_same<decltype(pt->end()), It_t>::value &&
std::is_same<decltype(cpt->begin()), CIt_t>::value && std::is_same<decltype(cpt->end()), CIt_t>::value &&
std::is_same<decltype(**pi), V_t &>::value && std::is_same<decltype(**pci), V_t const &>::value);
}

template <typename A>
static constexpr bool Test(...)
{
return false;
}

static constexpr bool value = Test<Test_t>(nullptr);
};

/// Check whether a histogram type is a classic or v7 histogram.
// FIXME true for all types that do not inherit from TH1
template <typename T>
struct IsV7Histo : public std::integral_constant<bool, !std::is_base_of<TH1, T>::value> {};

/// Lightweight storage for a collection of types.
/// Differently from std::tuple, no instantiation of objects of stored types is performed
template <typename... Types>
struct TypeList {
static constexpr std::size_t list_size = sizeof...(Types);
};

/// Extract types from the signature of a callable object.
template <typename T>
struct CallableTraits {
using arg_types = typename CallableTraits<decltype(&T::operator())>::arg_types;
using arg_types_nodecay = typename CallableTraits<decltype(&T::operator())>::arg_types_nodecay;
using ret_type = typename CallableTraits<decltype(&T::operator())>::ret_type;
};

// lambdas and std::function
template <typename R, typename T, typename... Args>
struct CallableTraits<R (T::*)(Args...) const> {
using arg_types = TypeList<typename std::decay<Args>::type...>;
using arg_types_nodecay = TypeList<Args...>;
using ret_type = R;
};

// mutable lambdas and functor classes
template <typename R, typename T, typename... Args>
struct CallableTraits<R (T::*)(Args...)> {
using arg_types = TypeList<typename std::decay<Args>::type...>;
using arg_types_nodecay = TypeList<Args...>;
using ret_type = R;
};

// function pointers
template <typename R, typename... Args>
struct CallableTraits<R (*)(Args...)> {
using arg_types = TypeList<typename std::decay<Args>::type...>;
using arg_types_nodecay = TypeList<Args...>;
using ret_type = R;
};

// free functions
template <typename R, typename... Args>
struct CallableTraits<R(Args...)> {
using arg_types = TypeList<typename std::decay<Args>::type...>;
using arg_types_nodecay = TypeList<Args...>;
using ret_type = R;
};

// Return first of a variadic list of types.
template <typename T, typename...Rest>
struct TakeFirst {
using type = T;
};

template <typename...Types>
using TakeFirst_t = typename TakeFirst<Types...>::type;

// Remove first type from a variadic list of types, return a TypeList containing the rest.
// e.g. RemoveFirst_t<A,B,C> is TypeList<B,C>
template<typename T, typename...Rest>
struct RemoveFirst {
using type = TypeList<Rest...>;
};

template<typename...Args>
using RemoveFirst_t = typename RemoveFirst<Args...>::type;

/// Return first of possibly many template parameters.
/// For non-template types, the result is the type itself.
/// e.g. TakeFirstParameter<U<A,B>> is A
/// TakeFirstParameter<T> is T
template <typename T>
struct TakeFirstParameter {
using type = void;
};

template <template <typename...> class Template, typename T, typename... Rest>
struct TakeFirstParameter<Template<T, Rest...>> {
using type = T;
};

template <typename T>
using TakeFirstParameter_t = typename TakeFirstParameter<T>::type;

/// Remove first of possibly many template parameters.
/// e.g. RemoveFirstParameter_t<U<A,B>> is U<B>
template <typename>
struct RemoveFirstParameter {
};

template <typename T, template <typename...> class U, typename...Rest>
struct RemoveFirstParameter<U<T, Rest...>> {
using type = U<Rest...>;
};

template <typename T>
using RemoveFirstParameter_t = typename RemoveFirstParameter<T>::type;

} // ns ROOT
} // ns TypeTraits
#endif //ROOT_TTypeTraits
121 changes: 11 additions & 110 deletions tree/treeplayer/inc/ROOT/TDFUtils.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,60 +43,23 @@ namespace Internal {
namespace TDF {
using namespace ROOT::Detail::TDF;

template <typename... Types>
struct TTypeList {
static constexpr std::size_t fgSize = sizeof...(Types);
};

// extract parameter types from a callable object
template <typename T>
struct TFunctionTraits {
using Args_t = typename TFunctionTraits<decltype(&T::operator())>::Args_t;
using ArgsNoDecay_t = typename TFunctionTraits<decltype(&T::operator())>::ArgsNoDecay_t;
using Ret_t = typename TFunctionTraits<decltype(&T::operator())>::Ret_t;
};

// lambdas and std::function
template <typename R, typename T, typename... Args>
struct TFunctionTraits<R (T::*)(Args...) const> {
using Args_t = TTypeList<typename std::decay<Args>::type...>;
using ArgsNoDecay_t = TTypeList<Args...>;
using Ret_t = R;
};

// mutable lambdas and functor classes
template <typename R, typename T, typename... Args>
struct TFunctionTraits<R (T::*)(Args...)> {
using Args_t = TTypeList<typename std::decay<Args>::type...>;
using ArgsNoDecay_t = TTypeList<Args...>;
using Ret_t = R;
};

// function pointers
template <typename R, typename... Args>
struct TFunctionTraits<R (*)(Args...)> {
using Args_t = TTypeList<typename std::decay<Args>::type...>;
using ArgsNoDecay_t = TTypeList<Args...>;
using Ret_t = R;
/// Compile-time integer sequence generator
/// e.g. calling GenStaticSeq<3>::type() instantiates a StaticSeq<0,1,2>
template <int...>
struct StaticSeq {
};

// free functions
template <typename R, typename... Args>
struct TFunctionTraits<R(Args...)> {
using Args_t = TTypeList<typename std::decay<Args>::type...>;
using ArgsNoDecay_t = TTypeList<Args...>;
using Ret_t = R;
template <int N, int... S>
struct GenStaticSeq : GenStaticSeq<N - 1, N - 1, S...> {
};

// remove first type from TTypeList
template <typename>
struct TRemoveFirst {
template <int... S>
struct GenStaticSeq<0, S...> {
using type = StaticSeq<S...>;
};

template <typename T, typename... Args>
struct TRemoveFirst<TTypeList<T, Args...>> {
using Types_t = TTypeList<Args...>;
};
template <int... S>
using GenStaticSeq_t = typename GenStaticSeq<S...>::type;

// return wrapper around f that prepends an `unsigned int slot` parameter
template <typename R, typename F, typename... Args>
Expand All @@ -105,63 +68,6 @@ std::function<R(unsigned int, Args...)> AddSlotParameter(F &f, TTypeList<Args...
return [f](unsigned int, Args... a) -> R { return f(a...); };
}

// compile-time integer sequence generator
// e.g. calling TGenStaticSeq<3>::type() instantiates a TStaticSeq<0,1,2>
template <int...>
struct TStaticSeq {
};

template <int N, int... S>
struct TGenStaticSeq : TGenStaticSeq<N - 1, N - 1, S...> {
};

template <int... S>
struct TGenStaticSeq<0, S...> {
using Type_t = TStaticSeq<S...>;
};

template <typename T>
struct TIsContainer {
using Test_t = typename std::decay<T>::type;

template <typename A>
static constexpr bool Test(A *pt, A const *cpt = nullptr, decltype(pt->begin()) * = nullptr,
decltype(pt->end()) * = nullptr, decltype(cpt->begin()) * = nullptr,
decltype(cpt->end()) * = nullptr, typename A::iterator *pi = nullptr,
typename A::const_iterator *pci = nullptr)
{
using It_t = typename A::iterator;
using CIt_t = typename A::const_iterator;
using V_t = typename A::value_type;
return std::is_same<Test_t, std::vector<bool>>::value ||
(std::is_same<decltype(pt->begin()), It_t>::value && std::is_same<decltype(pt->end()), It_t>::value &&
std::is_same<decltype(cpt->begin()), CIt_t>::value && std::is_same<decltype(cpt->end()), CIt_t>::value &&
std::is_same<decltype(**pi), V_t &>::value && std::is_same<decltype(**pci), V_t const &>::value);
}

template <typename A>
static constexpr bool Test(...)
{
return false;
}

static const bool fgValue = Test<Test_t>(nullptr);
};

// Extract first of possibly many template parameters. For non-template types, the result is the type itself
template <typename T>
struct TExtractType {
using type = T;
};

template <typename T, template <typename...> class U, typename... Extras>
struct TExtractType<U<T, Extras...>> {
using type = T;
};

template <typename T>
using ExtractType_t = typename TExtractType<T>::type;

template <typename BranchType, typename... Rest>
struct TNeedJitting {
static constexpr bool value = TNeedJitting<Rest...>::value;
Expand Down Expand Up @@ -287,11 +193,6 @@ struct Fill {
};
}

template <typename T, bool ISV7HISTO = !std::is_base_of<TH1, T>::value>
struct TIsV7Histo {
const static bool fgValue = ISV7HISTO;
};

template <typename T, bool ISV7HISTO = TIsV7Histo<T>::fgValue>
struct HistoUtils {
static void SetCanExtendAllAxes(T &h) { h.SetCanExtend(::TH1::kAllAxes); }
Expand Down