mirror of https://github.com/CGAL/cgal
New implementation for Has_member_*
This commit is contained in:
parent
d433b1d61e
commit
e5862bd189
|
|
@ -19,11 +19,8 @@ template<class T>
|
||||||
class Has_member_clear
|
class Has_member_clear
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
template<class U, U>
|
|
||||||
class check {};
|
|
||||||
|
|
||||||
template <class C>
|
template <class C>
|
||||||
static char f(check<void(C::*)(void), &C::clear>*);
|
static auto f(int) -> decltype(std::declval<C>().clear(), char());
|
||||||
|
|
||||||
template<class C>
|
template<class C>
|
||||||
static int f(...);
|
static int f(...);
|
||||||
|
|
|
||||||
|
|
@ -18,25 +18,14 @@ namespace internal {
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
class Has_member_id
|
class Has_member_id
|
||||||
{
|
{
|
||||||
typedef char yes[1];
|
template <typename U>
|
||||||
typedef char no[2];
|
static auto check(int) -> decltype(std::declval<U>().id(), char());
|
||||||
|
|
||||||
struct BaseWithId
|
|
||||||
{
|
|
||||||
void id(){}
|
|
||||||
};
|
|
||||||
struct Base : public Type, public BaseWithId {};
|
|
||||||
|
|
||||||
template <typename T, T t>
|
|
||||||
class Helper{};
|
|
||||||
|
|
||||||
template <typename U>
|
template <typename U>
|
||||||
static no &check(U*, Helper<void (BaseWithId::*)(), &U::id>* = 0);
|
static int check(...);
|
||||||
|
|
||||||
static yes &check(...);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const bool value = (sizeof(yes) == sizeof(check((Base*)(0))));
|
static const bool value = (sizeof(char) == sizeof(check<Type>(0)));
|
||||||
};
|
};
|
||||||
|
|
||||||
} // internal
|
} // internal
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ struct with_clear_but_args {
|
||||||
void clear(int) {}
|
void clear(int) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct with_clear_but_const {
|
struct with_clear_const {
|
||||||
void clear() const {}
|
void clear() const {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -25,7 +25,7 @@ int main()
|
||||||
|
|
||||||
CGAL_static_assertion(!Has_member_clear<with_clear_but_args>::value);
|
CGAL_static_assertion(!Has_member_clear<with_clear_but_args>::value);
|
||||||
|
|
||||||
CGAL_static_assertion(!Has_member_clear<with_clear_but_const>::value);
|
CGAL_static_assertion(Has_member_clear<with_clear_const>::value);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue