使用auto作为模板参数 [英] Using auto as a template parameter
问题描述
我试图使用GCC 4.7.1编译下面的 -std = c ++ 11
标志设置:
std :: map< std :: string,auto> myMap;
我试图创建一个对象来包含大量的各种类型的Json数据字符串,bool)以及子结构(列表,映射),所以我不能在编译时声明字段值的类型,所以我想我会使用 auto $ c
<$ p $ p>
错误:无效使用'auto'
错误:模板参数2无效
错误:模板参数4无效
错误:无法推断'auto 'from'< expression error>'
是否有特殊的方法使用 auto
作为模板参数,还是不可能?
正在寻找的是 boost :: any 。
std :: map< std :: string,boost :: any> myMap;
auto
可用作动态运行时类型。
I'm attempting to compile the following using GCC 4.7.1 with the -std=c++11
flag set:
std::map<std::string, auto> myMap;
I'm attempting to create an object to contain a large amount of Json data of various types (int string, bool) as well as sub-structures (list, map) so I can't declare the type of the field value at compile time, so I thought I'd use the auto
keyword for it.
However, when I try to compile it, I get the following
error: invalid use of ‘auto’
error: template argument 2 is invalid
error: template argument 4 is invalid
error: unable to deduce ‘auto’ from ‘<expression error>’
Is there a special way to use auto
as a template argument, or is it just not possible?
I think what you are looking for is boost::any.
std::map<std::string, boost::any> myMap;
auto
is evaluated during compile time and cannot be used as a dynamic run-time type.
这篇关于使用auto作为模板参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!