mirror of
https://github.com/Const-me/Whisper.git
synced 2026-10-17 04:30:30 +08:00
44 lines
2.4 KiB
C++
44 lines
2.4 KiB
C++
#pragma once
|
|
#include <type_traits>
|
|
|
|
namespace ComLight
|
|
{
|
|
namespace details
|
|
{
|
|
template<class TResult, class TValue>
|
|
constexpr bool pointersAssignable()
|
|
{
|
|
// See this for why `&` is required: https://stackoverflow.com/a/52429468/126995
|
|
return std::is_assignable<TResult*&, TValue*>::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<Derived>(nullptr)) == sizeof(Yes); \
|
|
}; \
|
|
\
|
|
template < class T > \
|
|
struct has_member_##member \
|
|
: public std::integral_constant<bool, HasMember_##member<T>::RESULT> \
|
|
{ \
|
|
};
|