New implementation for Has_member_*

This commit is contained in:
Laurent Rineau 2022-04-21 13:59:43 +02:00
parent d433b1d61e
commit e5862bd189
3 changed files with 8 additions and 22 deletions

View File

@ -19,11 +19,8 @@ template<class T>
class Has_member_clear class Has_member_clear
{ {
private: private:
template<class U, U> template <class C>
class check {}; static auto f(int) -> decltype(std::declval<C>().clear(), char());
template<class C>
static char f(check<void(C::*)(void), &C::clear>*);
template<class C> template<class C>
static int f(...); static int f(...);

View File

@ -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

View File

@ -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;
} }