可变模板 [英] dependent types with variadic templates
本文介绍了可变模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您可以看到此函数声明有什么问题吗?
模板< typename ... Containers>
std :: tuple< typename Containers :: value_type ...>
foo(const Containers& ... args);
当我尝试调用它,像这样:
foo(std :: list< int>(),std :: vector< float>());
MSVC2013说错误C2027:使用未定义类型'std :: tuple&容器:: value_type>
。
我尝试使用late return语法重写函数声明, >
有什么方法可以实现这个代码要做什么?
解决方案
p>您赢得了填写微软错误报告的权利连接 ...代码在clang和gcc上确定。
VS2013和gcc 4.7的解决方法:
< typename T>
使用ValueType = typename T :: value_type;
template< typename ... Containers>
std :: tuple< ValueType< Containers> ...>
foo(const Containers& ... args){return {}; }
Can you see anything wrong with this function declaration?
template<typename... Containers>
std::tuple<typename Containers::value_type...>
foo(const Containers &...args);
When I try to call it, like this:
foo(std::list<int>(), std::vector<float>());
MSVC2013 says error C2027: use of undefined type 'std::tuple<Containers::value_type>
.
I tried rewriting the function declaration with the "late return" syntax and it made no difference.
Is there any way I can achieve what this code is trying to do?
解决方案
You won the right to fill a bug report on microsoft connect… The code is ok on clang and gcc.
A workaround on VS2013 and maybe gcc 4.7 :
template <typename T>
using ValueType = typename T::value_type;
template<typename... Containers>
std::tuple<ValueType<Containers>...>
foo( const Containers &...args ) { return {}; }
这篇关于可变模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文