维基百科:Barton-Nackman技巧中使用的C++非模板成员是什么?
// A class template to express an equality comparison interface.
template<typename T> class equal_comparable
{
friend bool operator==(T const &a, T const &b) { return a.equal_to(b); }
friend bool operator!=(T const &a, T const &b) { return !a.equal_to(b); }
};
class value_type
// Class value_type wants to have == and !=, so it derives from
// equal_comparable with itself as argument (which is the CRTP).
: private equal_comparable<value_type>
{
public:
bool equal_to(value_type const& rhs) const; // to be defined
};
这应该是Barton-Nackman,即可以实现编译时量纲分析(检查是否适用于一些变量的操作最终在可比的数字,喜欢的速度不相上下空间/时间,但没有加速度)。
任何人都可以解释我如何,或者至少解释我什么是非模板成员?
感谢
谢谢,这有助于我理解它。 – alvatar 2009-05-20 10:46:11