Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initializing map of maps with initializer list in VS 2013

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?

like image 910
omikron Avatar asked Oct 09 '13 10:10

omikron


1 Answers

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.

like image 77
Stephan T. Lavavej Avatar answered Oct 20 '22 01:10

Stephan T. Lavavej