From 8c4603c73675958efc960fbd4bb599a2909d106a Mon Sep 17 00:00:00 2001 From: Konstantin Date: Mon, 16 Jan 2023 14:52:43 +0100 Subject: Source codes --- ComLightLib/utils/typeTraits.hpp | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 ComLightLib/utils/typeTraits.hpp (limited to 'ComLightLib/utils/typeTraits.hpp') diff --git a/ComLightLib/utils/typeTraits.hpp b/ComLightLib/utils/typeTraits.hpp new file mode 100644 index 0000000..c5ddb84 --- /dev/null +++ b/ComLightLib/utils/typeTraits.hpp @@ -0,0 +1,43 @@ +#pragma once +#include + +namespace ComLight +{ + namespace details + { + template + constexpr bool pointersAssignable() + { + // See this for why `&` is required: https://stackoverflow.com/a/52429468/126995 + return std::is_assignable::value; + } + } +} + +// https://en.wikibooks.org/wiki/More_C++_Idioms/Member_Detector +#define GENERATE_HAS_MEMBER(member) \ + \ +template < class T > \ +class HasMember_##member \ +{ \ +private: \ + using Yes = char[2]; \ + using No = char[1]; \ + \ + struct Fallback { int member; }; \ + struct Derived : T, Fallback { }; \ + \ + template < class U > \ + static No& test ( decltype(U::member)* ); \ + template < typename U > \ + static Yes& test ( U* ); \ + \ +public: \ + static constexpr bool RESULT = sizeof(test(nullptr)) == sizeof(Yes); \ +}; \ + \ +template < class T > \ +struct has_member_##member \ +: public std::integral_constant::RESULT> \ +{ \ +}; -- cgit v1.2.3