我想知道是否可以检测模板类容器类型,并重新定义其参数。例如:
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/