@abilitytao
可以使用policy based做比较
template<typename element_t>
struct less_than {
static bool compare(const element_t lhs, const element_t rhs) {
return lhs<rhs;
}
};
template<typename element_t, typename cmp_policy = less_than<element_t> >
struct sort_wirzad {
void easy_sort() {
...
//做比较
if ( cmp_policy::compare(e1,e2) ) { /* do sth */ }
}
};
用户可以自定义自己的 compare_policy
比如定义一个 greater_than 可以这样传递给sort_wizard:
sort_wizard<int,greater_than> instance;