【发布时间】:2019-11-13 01:41:51
【问题描述】:
我有以下课程:
class Conversion {
//...
public:
template<class T,
template<class, class = std::allocator<T>> class> T doTheWork()
{
//do the work
return {};
}
};
我想将内容复制到一个顺序容器(向量、列表、双端队列),声明为:
template<class T, class Allocator = std::allocator<T>>
我对模板声明感到困惑。
考虑到我想将接收者作为以下示例,我应该如何声明copyContentToContainer?
例子:
int main() {
Conversion conv;
std::vector<std::string> container1 = conv.doTheWork();
std::list<int> container2 = conv.doTheWork();
std::deque<double> container3 = conv.doTheWork();
}
【问题讨论】:
-
您可以使用答案here 中使用的技巧,您可以使用模板化转换运算符返回代理类型
标签: c++ c++11 templates c++14 std