【发布时间】:2015-05-04 22:07:37
【问题描述】:
我正在尝试编写一个std::sort 模板比较类,它应该接收未知数量的元组(可变参数模板)。每个元组应该由一个列(我们的代码中的某种类型)和一个 bool 组成,指定该列是按升序还是降序排序。
基本上,我想要类似的东西:
// 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 中可能吗?
【问题讨论】:
-
@BaummitAugen 因为稍后我想根据列类型添加模板专业化(应该提到)
-
不应该
operator()采取tuple<>吗?这只能用于对整数进行排序... -
@Barry 它对整数进行排序,但相对于作为模板参数传递的列(整数表示行索引,列表示要排序的列)
-
我不知道“关于列”是什么意思。你能举个例子吗?