我正在尝试编写一个std::sort
模板比较类,该类应该接收未知数量的元组(可变模板)。每个元组都应由一列(在我们的代码中具有某种类型)和布尔组成,并指定该列应按升序还是降序排序。
基本上,我想要类似的东西:
// doesn't compile - conceptual code
template <typename std::tuple<Col, bool>>
struct Comparator
{
bool operator() (int lhs, int rhs)
{
// lhs and rhs are row indices. Depending on the columns
// and the bools received, decide which index should come first
}
}
在C ++ 11中这种事情可能吗?
是的,有可能-您想要部分专业化Comparator
:
template <typename T>
struct Comparator;
template <typename Col>
struct Comparator<std::tuple<Col, bool>>
{
// ...
};
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句