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
|
||||
{
|
||||
private:
|
||||
template<class U, U>
|
||||
class check {};
|
||||
|
||||
template<class C>
|
||||
static char f(check<void(C::*)(void), &C::clear>*);
|
||||
template <class C>
|
||||
static auto f(int) -> decltype(std::declval<C>().clear(), char());
|
||||
|
||||
template<class C>
|
||||
static int f(...);
|
||||
|
|
|
|||
|
|
@ -18,25 +18,14 @@ namespace internal {
|
|||
template <typename Type>
|
||||
class Has_member_id
|
||||
{
|
||||
typedef char yes[1];
|
||||
typedef char no[2];
|
||||
|
||||
struct BaseWithId
|
||||
{
|
||||
void id(){}
|
||||
};
|
||||
struct Base : public Type, public BaseWithId {};
|
||||
|
||||
template <typename T, T t>
|
||||
class Helper{};
|
||||
template <typename U>
|
||||
static auto check(int) -> decltype(std::declval<U>().id(), char());
|
||||
|
||||
template <typename U>
|
||||
static no &check(U*, Helper<void (BaseWithId::*)(), &U::id>* = 0);
|
||||
|
||||
static yes &check(...);
|
||||
static int check(...);
|
||||
|
||||
public:
|
||||
static const bool value = (sizeof(yes) == sizeof(check((Base*)(0))));
|
||||
static const bool value = (sizeof(char) == sizeof(check<Type>(0)));
|
||||
};
|
||||
|
||||
} // internal
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ struct with_clear_but_args {
|
|||
void clear(int) {}
|
||||
};
|
||||
|
||||
struct with_clear_but_const {
|
||||
struct with_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_const>::value);
|
||||
CGAL_static_assertion(Has_member_clear<with_clear_const>::value);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue