dependent types with variadic templates

风格不统一 提交于 2020-01-04 02:54:07

问题


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?


回答1:


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 {}; }


来源:https://stackoverflow.com/questions/21607167/dependent-types-with-variadic-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!