std :: tuple作为模板参数?

Shmoopy

我正在尝试编写一个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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在std :: tuple <...>上实现map()和each()-将索引作为模板参数传递给functor

std :: function作为模板模板参数

C ++:&(std :: cout)作为模板参数

C++ std::plus 作为模板参数

std::function vs callable 作为模板参数

std :: array作为类的模板参数

如何从可变参数模板参数创建std :: tuple <>?

将以可变参数模板参数为元素类型的std :: tuple传递给另一个函数作为参数列表

为什么`std :: pair`将`std :: tuple`作为ctor参数类型而不是`const std :: tuple&`?

std:map作为模板参数的模板推导失败

可变参数模板作为std :: function的参数

使用std :: function作为参数的可变参数模板

可变参数模板展开到std :: tuple

std :: source_location作为非类型模板参数

如何使用std :: chrono :: duration作为模板参数?

使用std :: array <Type,N>的实例作为模板参数

为什么在std :: tuple和模板派生类中模板参数推导/替换失败?

使用std :: enable_if和std :: is_arithmetic作为模板参数的问题

将std :: vector作为模板模板参数传递时出错-在GCC中工作,在MSVC中失败

将std :: type_index作为模板参数传递给函数模板

std :: tuple vs std :: array作为std :: vector的项

从作为模板函数参数传递的std :: function推断返回值和参数类型?

通过模板参数给定其长度,在编译时生成相同类型的std :: tuple

使用std :: get作为std :: transform的参数

模仿std :: function模板参数

std :: function模板参数推导

std::function 中的模板参数

C ++ 11:从模板函数构建std :: tuple

std :: pair中的模板模板参数