codec/include/nil/crypto3/detail/type_traits.hpp File Reference
Go to the source code of this file.
Namespaces | |
nil | |
nil::crypto3 | |
nil::crypto3::detail | |
Macros | |
#define | GENERATE_HAS_MEMBER(member) |
#define | GENERATE_HAS_MEMBER_CONST_FUNCTION(Function, ...) |
#define | GENERATE_HAS_MEMBER_CONST_RETURN_FUNCTION(Function, ReturnType, ...) |
#define | GENERATE_HAS_MEMBER_FUNCTION(Function, ...) |
#define | GENERATE_HAS_MEMBER_RETURN_FUNCTION(Function, ReturnType, ...) |
#define | GENERATE_HAS_MEMBER_TYPE(Type) |
Macro Definition Documentation
◆ GENERATE_HAS_MEMBER
#define GENERATE_HAS_MEMBER | ( | member | ) |
Value:
\
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 : public std::integral_constant<bool, HasMember_##member<T>::RESULT> { };
◆ GENERATE_HAS_MEMBER_CONST_FUNCTION
#define GENERATE_HAS_MEMBER_CONST_FUNCTION | ( | Function, | |
... | |||
) |
Value:
\
template<typename T> \
struct has_##Function { \
struct Fallback { \
void Function(##__VA_ARGS__) const; \
}; \
\
struct Derived : Fallback { }; \
\
template<typename C, C> \
struct ChT; \
\
template<typename C> \
static char (&f(ChT<void (Fallback::*)(##__VA_ARGS__) const, &C::Function> *))[1]; \
\
template<typename C> \
static char (&f(...))[2]; \
\
static bool const value = sizeof(f<Derived>(0)) == 2; \
};
◆ GENERATE_HAS_MEMBER_CONST_RETURN_FUNCTION
#define GENERATE_HAS_MEMBER_CONST_RETURN_FUNCTION | ( | Function, | |
ReturnType, | |||
... | |||
) |
Value:
\
template<typename T> \
struct has_##Function { \
struct Dummy { \
typedef void ReturnType; \
}; \
typedef typename std::conditional<has_##ReturnType<T>::value, T, Dummy>::type TType; \
typedef typename TType::ReturnType type; \
\
struct Fallback { \
type Function(##__VA_ARGS__) const; \
}; \
\
struct Derived : TType, Fallback { }; \
\
template<typename C, C> \
struct ChT; \
\
template<typename C> \
static char (&f(ChT<type (Fallback::*)(##__VA_ARGS__) const, &C::Function> *))[1]; \
\
template<typename C> \
static char (&f(...))[2]; \
\
static bool const value = sizeof(f<Derived>(0)) == 2; \
};
◆ GENERATE_HAS_MEMBER_FUNCTION
#define GENERATE_HAS_MEMBER_FUNCTION | ( | Function, | |
... | |||
) |
Value:
\
template<typename T> \
struct has_##Function { \
struct Fallback { \
void Function(##__VA_ARGS__); \
}; \
\
struct Derived : Fallback { }; \
\
template<typename C, C> \
struct ChT; \
\
template<typename C> \
static char (&f(ChT<void (Fallback::*)(##__VA_ARGS__), &C::Function> *))[1]; \
\
template<typename C> \
static char (&f(...))[2]; \
\
static bool const value = sizeof(f<Derived>(0)) == 2; \
};
◆ GENERATE_HAS_MEMBER_RETURN_FUNCTION
#define GENERATE_HAS_MEMBER_RETURN_FUNCTION | ( | Function, | |
ReturnType, | |||
... | |||
) |
Value:
\
template<typename T> \
struct has_##Function { \
struct Dummy { \
typedef void ReturnType; \
}; \
typedef typename std::conditional<has_##ReturnType<T>::value, T, Dummy>::type TType; \
typedef typename TType::ReturnType type; \
\
struct Fallback { \
type Function(##__VA_ARGS__); \
}; \
\
struct Derived : TType, Fallback { }; \
\
template<typename C, C> \
struct ChT; \
\
template<typename C> \
static char (&f(ChT<type (Fallback::*)(##__VA_ARGS__), &C::Function> *))[1]; \
\
template<typename C> \
static char (&f(...))[2]; \
\
static bool const value = sizeof(f<Derived>(0)) == 2; \
};
◆ GENERATE_HAS_MEMBER_TYPE
#define GENERATE_HAS_MEMBER_TYPE | ( | Type | ) |
Value:
\
template<class T> \
class HasMemberType_##Type { \
private: \
using Yes = char[2]; \
using No = char[1]; \
\
struct Fallback { \
struct Type { }; \
}; \
struct Derived : T, Fallback { }; \
\
template<class U> \
static No &test(typename U::Type *); \
template<typename U> \
static Yes &test(U *); \
\
public: \
static constexpr bool RESULT = sizeof(test<Derived>(nullptr)) == sizeof(Yes); \
}; \
\
template<class T> \
struct has_##Type : public std::integral_constant<bool, HasMemberType_##Type<T>::RESULT> { };