Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1763026
  • 博文数量: 100
  • 博客积分: 10122
  • 博客等级: 上将
  • 技术积分: 4092
  • 用 户 组: 普通用户
  • 注册时间: 2005-07-04 20:28
文章分类

全部博文(100)

文章存档

2010年(2)

2009年(28)

2008年(70)

我的朋友

分类: C/C++

2009-10-30 23:04:21

#include 
#include
#include
#include hpp>


/* 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
::operator ->)>* = NULL);

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?

阅读(1245) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~