minor tweaks in has_* helpers

This commit is contained in:
Gael Guennebaud 2016-08-31 23:04:14 +02:00
parent 7ae819123c
commit 84cf6e42ca

View File

@ -368,29 +368,26 @@ struct result_of<Func(ArgType0,ArgType1,ArgType2)> {
};
#endif
struct meta_yes { char a[1]; };
struct meta_no { char a[2]; };
// Check whether T::ReturnType does exist
template <typename T>
struct has_ReturnType
{
typedef char yes[1];
typedef char no[2];
template <typename C> static meta_yes testFunctor(typename C::ReturnType const *);
template <typename C> static meta_no testFunctor(...);
template <typename C> static yes& testFunctor(typename C::ReturnType const *);
template <typename C> static no& testFunctor(...);
enum { value = sizeof(testFunctor<T>(0)) == sizeof(yes) };
enum { value = sizeof(testFunctor<T>(0)) == sizeof(meta_yes) };
};
template<int> struct any_int {};
template<int Val> struct integral_constant { static const int value = Val; };
template<typename T> const T& return_ref();
struct meta_yes { char data[1]; };
struct meta_no { char data[2]; };
template <typename T>
struct has_nullary_operator
{
template <typename C> static meta_yes testFunctor(C const *,any_int< sizeof(return_ref<C>()()) > * = 0);
template <typename C> static meta_yes testFunctor(C const *,integral_constant< sizeof(return_ref<C>()()) > * = 0);
static meta_no testFunctor(...);
enum { value = sizeof(testFunctor(static_cast<T*>(0))) == sizeof(meta_yes) };
@ -399,7 +396,7 @@ struct has_nullary_operator
template <typename T>
struct has_unary_operator
{
template <typename C> static meta_yes testFunctor(C const *,any_int< sizeof(return_ref<C>()(Index(0))) > * = 0);
template <typename C> static meta_yes testFunctor(C const *,integral_constant< sizeof(return_ref<C>()(Index(0))) > * = 0);
static meta_no testFunctor(...);
enum { value = sizeof(testFunctor(static_cast<T*>(0))) == sizeof(meta_yes) };
@ -408,7 +405,7 @@ struct has_unary_operator
template <typename T>
struct has_binary_operator
{
template <typename C> static meta_yes testFunctor(C const *,any_int< sizeof(return_ref<C>()(Index(0),Index(0))) > * = 0);
template <typename C> static meta_yes testFunctor(C const *,integral_constant< sizeof(return_ref<C>()(Index(0),Index(0))) > * = 0);
static meta_no testFunctor(...);
enum { value = sizeof(testFunctor(static_cast<T*>(0))) == sizeof(meta_yes) };