分类: C/C++
2009-10-30 23:04:21
#include
#include
#include
#includehpp> ::operator ->)>* = NULL);
/* type trait : has_arrow_operator*/
template <typename T>
struct has_arrow_operator {
template <typename> struct test;
template<typename U>
static boost::type_traits::yes_type check_sig(testU
template<typename U>
static boost::type_traits::no_type check_sig(...);
static const bool value = sizeof(check_sig<T>(0)) == sizeof(boost::type_traits::yes_type);
};
/* operator -> available */
class A {
public:
A* operator -> ();
};
/* operator -> hidden */
class B {
protected:
B* operator -> ();
};
/* operator -> not available */
class C {
};
int main() {
std::cout << has_arrow_operator<int>::value << std::endl;
std::cout << has_arrow_operator<boost::shared_ptr<int> >::value << std::endl;
std::cout << has_arrow_operator<A>::value << std::endl;
// ????? how to make this false
//std::cout << has_arrow_operator::value << std::endl;
std::cout << has_arrow_operator<C>::value << std::endl;
}
Executing result:
$ dync++ has_arrow_operator.cpp
0
1
1
0
Question is how to make the private operator version class B works also?