From 74a7fb2169570451c6ac015c2c16037bd1a866bb Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <github@naumov.de> Date: Thu, 20 Oct 2022 17:44:31 +0200 Subject: [PATCH] [PL/Refl] Replace TMP HasReflect with requires More concise implementation. --- ProcessLib/Reflection/ReflectionIPData.h | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/ProcessLib/Reflection/ReflectionIPData.h b/ProcessLib/Reflection/ReflectionIPData.h index a301b8f3b7d..7e1e2865bc6 100644 --- a/ProcessLib/Reflection/ReflectionIPData.h +++ b/ProcessLib/Reflection/ReflectionIPData.h @@ -20,18 +20,10 @@ namespace ProcessLib::Reflection namespace detail { // Used in metaprogramming to check if the type T has a member "reflect". -// Implementation based on https://stackoverflow.com/a/257382 template <typename T> -class HasReflect +constexpr bool has_reflect = requires { - template <typename C> - static char test(decltype(&C::reflect)); - - template <typename C> - static double test(...); - -public: - static constexpr bool value = sizeof(test<T>(nullptr)) == sizeof(char); + T::reflect(); }; template <typename T> @@ -271,7 +263,7 @@ void forEachReflectedFlattenedIPDataAccessor( level; }; - if constexpr (HasReflect<Member>::value) + if constexpr (has_reflect<Member>) { forEachReflectedFlattenedIPDataAccessor<Dim>( callback, Member::reflect(), @@ -332,7 +324,7 @@ void forEachReflectedFlattenedIPDataAccessor(ReflData const& reflection_data, return loc_asm.*ip_data_vector; }; - if constexpr (detail::HasReflect<Member>::value) + if constexpr (detail::has_reflect<Member>) { detail::forEachReflectedFlattenedIPDataAccessor<Dim>( callback, Member::reflect(), -- GitLab