东西太多,有必要停下来仔细看一下几个基本的模板类,这里先看一下add_value_*模板。
template< class T, int I > struct add_value_2
{
typedef boost::arg type;
};
template< class T > struct add_value_2< T, 0 >
{
typedef _bi::value< T > type;
};
template
{
typedef typename add_value_2< T, boost::is_placeholder< T >::value >::type type;
};
这是个模板特化应用。当传递boost::arg
当为0的时候,编译器则找到add_value_2
template
{
public:
value(T const & t): t_(t) {}
T & get() { return t_; }
T const & get() const { return t_; }
bool operator==(value const & rhs) const
{
return t_ == rhs.t_;
}
private:
T t_;
};
这个模板很简单,我们经常写的。把T类型的参数保存为成员变量,提供get方法获取该变量。也提供了拷贝赋值函数。
因此在为0的情况下,type类型就是_bi::value
否则使用第一个add_value_2模板,这时候类型add_value_2::type就是boost::arg
总结:
add_value模板的功能是接受boost::arg
如果T模板参数不是boost::arg