From 87a8f81a8a5d2488e4b114642c984a89fa4c6bd1 Mon Sep 17 00:00:00 2001 From: Joris Vaillant <joris.vaillant@inria.fr> Date: Thu, 1 Feb 2024 15:25:56 +0100 Subject: [PATCH] core: Move is_class_or_union trait in utils/traits.hpp --- include/eigenpy/utils/traits.hpp | 30 ++++++++++++++++++++++++++++++ include/eigenpy/variant.hpp | 13 +------------ 2 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 include/eigenpy/utils/traits.hpp diff --git a/include/eigenpy/utils/traits.hpp b/include/eigenpy/utils/traits.hpp new file mode 100644 index 00000000..9ce6b4fa --- /dev/null +++ b/include/eigenpy/utils/traits.hpp @@ -0,0 +1,30 @@ +// +// Copyright (c) 2024 INRIA +// +// +#include <type_traits> + +#ifndef __eigenpy_utils_traits_hpp__ +#define __eigenpy_utils_traits_hpp__ + +namespace eigenpy { + +namespace details { + +/// Trait to detect if T is a class or an union +template <typename T> +struct is_class_or_union + : std::integral_constant<bool, std::is_class<T>::value || + std::is_union<T>::value> {}; + +/// Trait to remove cvref and call is_class_or_union +template <typename T> +struct is_class_or_union_remove_cvref + : is_class_or_union<typename std::remove_cv< + typename std::remove_reference<T>::type>::type> {}; + +} // namespace details + +} // namespace eigenpy + +#endif // ifndef __eigenpy_utils_traits_hpp__ diff --git a/include/eigenpy/variant.hpp b/include/eigenpy/variant.hpp index 4028f856..f989a0f9 100644 --- a/include/eigenpy/variant.hpp +++ b/include/eigenpy/variant.hpp @@ -6,6 +6,7 @@ #define __eigenpy_utils_variant_hpp__ #include "eigenpy/fwd.hpp" +#include "eigenpy/utils/traits.hpp" #include <boost/python.hpp> #include <boost/variant.hpp> @@ -204,18 +205,6 @@ struct VariantValueToObject : VariantVisitorType<PyObject*, Variant> { using Base::operator(); }; -/// Trait to detect if T is a class or an union -template <typename T> -struct is_class_or_union - : std::integral_constant<bool, std::is_class<T>::value || - std::is_union<T>::value> {}; - -/// Trait to remove cvref and call is_class_or_union -template <typename T> -struct is_class_or_union_remove_cvref - : is_class_or_union<typename std::remove_cv< - typename std::remove_reference<T>::type>::type> {}; - /// Convert {boost,std}::variant<class...> alternative reference to a Python /// object. This converter return the alternative reference. The code that /// create the reference holder is taken from \see -- GitLab