std :: map中有typedef类型吗?

Ton*_*ion 1 c++ typedef map

在C++中执行以下操作是一个好主意:

typedef std::map<std::string, boost::any> MyVals;

// Is the following typedef'd type inside a map a good idea?
typedef std::map<std::string, MyVals> TagValues;  
Run Code Online (Sandbox Code Playgroud)

这些地图将用于顺序插入和删除.

Vla*_*lad 7

typedefing代码中常用的类型没什么不好的.

Typedef仅存在于语法层面,它们不会对生成的代码进行任何更改.此外,精心挑选的名称将使可读性更好.

只是比较

std::map<std::string, std::map<std::string, boost::any>::const_iterator it =
         tagValues.find(x);
Run Code Online (Sandbox Code Playgroud)

TagValue::const_iterator it = tagValues.find(x);
Run Code Online (Sandbox Code Playgroud)