diff --git a/core/foundation/CMakeLists.txt b/core/foundation/CMakeLists.txt index d877d99c76c79..138b67ffd6000 100644 --- a/core/foundation/CMakeLists.txt +++ b/core/foundation/CMakeLists.txt @@ -18,3 +18,8 @@ ROOT_OBJECT_LIBRARY(Foundation_Stage1 ${sources}) # used by rootcling_stage1 set_target_properties(Foundation_Stage1 PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} ${CLING_CXXFLAGS}") ROOT_INSTALL_HEADERS() + +if(testing) + add_subdirectory(test) +endif() + diff --git a/core/foundation/inc/ROOT/TTypeTraits.hxx b/core/foundation/inc/ROOT/TTypeTraits.hxx deleted file mode 100644 index df5108162739d..0000000000000 --- a/core/foundation/inc/ROOT/TTypeTraits.hxx +++ /dev/null @@ -1,30 +0,0 @@ -// @(#)root/foundation: -// Author: Axel Naumann, 2017-06-02 - -/************************************************************************* - * Copyright (C) 1995-2017, Rene Brun and Fons Rademakers. * - * All rights reserved. * - * * - * For the licensing terms see $ROOTSYS/LICENSE. * - * For the list of contributors see $ROOTSYS/README/CREDITS. * - *************************************************************************/ - -#ifndef ROOT_TTypeTraits -#define ROOT_TTypeTraits - -#include - -namespace ROOT{ - -///\class ROOT::TypeTraits:: -template -class IsSmartOrDumbPtr: public std::integral_constant::value> {}; - -template -class IsSmartOrDumbPtr>: public std::true_type {}; - -template -class IsSmartOrDumbPtr>: public std::true_type {}; - -} -#endif //ROOT_TTypeTraits diff --git a/core/foundation/inc/ROOT/TypeTraits.hxx b/core/foundation/inc/ROOT/TypeTraits.hxx new file mode 100644 index 0000000000000..8e4b6099a1d1e --- /dev/null +++ b/core/foundation/inc/ROOT/TypeTraits.hxx @@ -0,0 +1,165 @@ +// @(#)root/foundation: +// Author: Axel Naumann, Enrico Guiraud, June 2017 + +/************************************************************************* + * Copyright (C) 1995-2017, Rene Brun and Fons Rademakers. * + * All rights reserved. * + * * + * For the licensing terms see $ROOTSYS/LICENSE. * + * For the list of contributors see $ROOTSYS/README/CREDITS. * + *************************************************************************/ + +#ifndef ROOT_TypeTraits +#define ROOT_TypeTraits + +#include // shared_ptr, unique_ptr for IsSmartOrDumbPtr +#include +#include // for IsContainer + +namespace ROOT { + +/// ROOT type_traits extensions +namespace TypeTraits { + +///\class ROOT::TypeTraits:: +template +class IsSmartOrDumbPtr : public std::integral_constant::value> { +}; + +template +class IsSmartOrDumbPtr> : public std::true_type { +}; + +template +class IsSmartOrDumbPtr> : public std::true_type { +}; + +/// Check for container traits. +template +struct IsContainer { + using Test_t = typename std::decay::type; + + template + 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>::value || + (std::is_samebegin()), It_t>::value && std::is_sameend()), It_t>::value && + std::is_samebegin()), CIt_t>::value && std::is_sameend()), CIt_t>::value && + std::is_same::value && std::is_same::value); + } + + template + static constexpr bool Test(...) + { + return false; + } + + static constexpr bool value = Test(nullptr); +}; + +/// Lightweight storage for a collection of types. +/// Differently from std::tuple, no instantiation of objects of stored types is performed +template +struct TypeList { + static constexpr std::size_t list_size = sizeof...(Types); +}; + +/// Extract types from the signature of a callable object. +template +struct CallableTraits { + using arg_types = typename CallableTraits::arg_types; + using arg_types_nodecay = typename CallableTraits::arg_types_nodecay; + using ret_type = typename CallableTraits::ret_type; +}; + +// lambdas and std::function +template +struct CallableTraits { + using arg_types = TypeList::type...>; + using arg_types_nodecay = TypeList; + using ret_type = R; +}; + +// mutable lambdas and functor classes +template +struct CallableTraits { + using arg_types = TypeList::type...>; + using arg_types_nodecay = TypeList; + using ret_type = R; +}; + +// function pointers +template +struct CallableTraits { + using arg_types = TypeList::type...>; + using arg_types_nodecay = TypeList; + using ret_type = R; +}; + +// free functions +template +struct CallableTraits { + using arg_types = TypeList::type...>; + using arg_types_nodecay = TypeList; + using ret_type = R; +}; + +// Return first of a variadic list of types. +template +struct TakeFirstType { + using type = T; +}; + +template +using TakeFirstType_t = typename TakeFirstType::type; + +// Remove first type from a variadic list of types, return a TypeList containing the rest. +// e.g. RemoveFirst_t is TypeList +template +struct RemoveFirst { + using type = TypeList; +}; + +template +using RemoveFirst_t = typename RemoveFirst::type; + +/// Return first of possibly many template parameters. +/// For non-template types, the result is the type itself. +/// e.g. TakeFirstParameter> is A +/// TakeFirstParameter is T +template +struct TakeFirstParameter { + using type = void; +}; + +template