可以在其中任何基本类型的地图 [英] map that can take any basic type inside

查看:105
本文介绍了可以在其中任何基本类型的地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个可以包含任何基本数据类型(如double,float,string,char等)的地图,以存储来自服务器组件请求的值。

I need to create a map that can contain as its value any basic data type such as double,float,string, char etc... to store values from a request for a server component.

我正在考虑使用这样的地图: std :: map< std :: string,void *> ,但是我不知道这是一个很好的解决方案。

I was thinking of using a map such as this: std::map<std::string, void*>, however I don't know that this is a very good solution.

我想知道有没有人可以提供更好的解决方案。要点是这些值必须在同一个地图上。

I wondered if anyone can advice on a better solution. The main point is that the values have to be in the same map.

请指教?

推荐答案

您可以使用 boost :: any 作为可以保存任何类型的值。

You could use boost::any as the value which can hold "any" type.

最好使用 boost :: variant ,如果只有有限的许多基本数据类型)

(It is better to use boost::variant if there are only finitely many "basic data types")

这篇关于可以在其中任何基本类型的地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆