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
};
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*
};
works properly.
Why this doesn't work when I have more than one pair in map? How to do it better?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With