c++ - 是否可以在 C++ 中提取容器模板类?

标签 c++ templates traits

我想知道是否可以检测模板类容器类型,并重新定义其参数。例如:

typedef std::vector<int> vint;
typedef typeget<vint>::change_param<double> vdouble;

vdouble 现在是 std::vector<double>

最佳答案

添加到@Kerrek SB 的回答中,这是通用方法:

template<typename...> struct rebinder;

template<template<typename...> class Container, typename ... Args>
struct rebinder<Container<Args...>>{
    template<typename ... UArgs>
    using rebind = Container<UArgs...>;
};

这适用于阳光下的任何容器。

关于c++ - 是否可以在 C++ 中提取容器模板类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33281903/

相关文章:

c++ - 如何将 "normal"C++ 类转换为模板?

rust - 类型绑定(bind) "not implemented"中的特征?

unit-testing - 当 PartialEq 的实现不合适时,如何断言两个变量相等?

c++ - 如何在 Windows 上从 C++ 控制台应用程序打印 UTF-8

c++ - 海量数据分析

c++ - 可修改的左值?

c++ - 使用 Eigen C++ 库求逆矩阵 mod-26

c++ - 查找 C++ 模板标识符列表的末尾

C++ 模板完全特化语法

scala - 解析命令行参数并在 scala 中执行函数