Initializing map of maps with initializer list in VS 2013(在 VS 2013 中使用初始化列表初始化地图映射)
问题描述
我正在尝试使用 C++11 初始化地图.我的编译器是 VS 2013 Express.
I'm trying to initialize map of maps using C++11. My compiler is VS 2013 Express.
unordered_map<EnumType, unordered_map<string, string>> substitutions = {
{
Record::BasementType,
{
{ "0", "" },
{ "1", "Slab or pier" },
{ "2", "Crawl" }
}
},
{
Record::BuildingStyle,
{
{ "0", "" },
{ "1", "Ranch" },
{ "2", "Raised ranch" }
}
},
// ... and so on
};
它已编译,但我在 ntdll.dll 中遇到断点.但是此代码的简化版本:
It's compile but I'm getting breakpoint inside ntdll.dll. However simplified version of this code:
unordered_map<EnumType, unordered_map<string, string>> substitutions = {
{
Record::BasementType,
{
{ "0", "" },
{ "1", "Slab or pier" },
{ "2", "Crawl" }
}
},
// *nothing more*
};
工作正常.
为什么当我在地图上有不止一对时这不起作用?如何做得更好?
Why this doesn't work when I have more than one pair in map? How to do it better?
推荐答案
这是一个已知的编译器错误,http://connect.microsoft.com/VisualStudio/feedback/details/800104/ .编译器会被初始化列表中的临时对象弄糊涂,甚至可以反复销毁单个对象.因为这是无声的糟糕代码生成,我已经要求编译器团队优先解决这个问题.
This is a known compiler bug, http://connect.microsoft.com/VisualStudio/feedback/details/800104/ . The compiler gets confused by temporaries in initializer lists, and can even destroy an individual object repeatedly. Because this is silent bad codegen, I've asked the compiler team to prioritize fixing this.
这篇关于在 VS 2013 中使用初始化列表初始化地图映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 VS 2013 中使用初始化列表初始化地图映射
- C++ 协变模板 2021-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 从python回调到c++的选项 2022-11-16
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 静态初始化顺序失败 2022-01-01
- 近似搜索的工作原理 2021-01-01