将初始化列表与std :: map一起使用

abe*_*nky 5 c++ visual-studio c++11 visual-studio-2013

我问了一个早先的问题,这个问题在CString和Unicode问题上脱离了主题.
我现在已经减少我的例子namespace stdcout(代替printf).
但核心问题仍然存在.

这与提名为重复问题有关,但是分开.这个问题是关于地图中的地图,并且已经超过2年了,注意问题是编译器团队的优先事项.(显然这不是一个优先事项)
这个问题值得保持开放

我正确使用初始化器吗?
有没有一个简单的方法来解决这个没有一个主要的解决方法?
(这是一个基于更复杂程序的最小示例)

#include <map>
#include <string>
#include <iostream>

struct Params
{
    int         inputType;
    std::string moduleName;
};

int main()
{
    std::map<std::string, Params> options{
        { "Add",       { 30, "RecordLib" } },
        { "Open",      { 40, "ViewLib"   } },
        { "Close",     { 50, "EditLib"   } },
        { "Inventory", { 60, "ControlLib"} },
        { "Report",    { 70, "ReportLib" } }
    };

    for (const auto& pair : options)
    {
        std::cout << "Entry: " << pair.first << " ==> { " << pair.second.moduleName << "    }" << std::endl;
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

产量

Entry:  ==> {  }
Entry: Report ==> {    }
Run Code Online (Sandbox Code Playgroud)

你只能看到最后的字符串"Report"幸存下来.

它真的在我看来像初始化列表std::map只是打破了.

我正在使用带有Unicode的Microsoft Visual Studio 2013.
这种情况发生在DebugRelease构建中,Optimizations Disabled或者/O2 相同的代码在IDEOne正常工作

abe*_*nky 4

Slava的坚持下,我与演员一起找到了一个简单的解决方案:

#include <map>
#include <string>
#include <iostream>

struct Params
{
    int         inputType;
    std::string moduleName;
    Params(const int n, const std::string& s) :
        inputType(n),
        moduleName(s)
    { }
};

int main()
{
    std::map<std::string, Params> options = {
        { "Add",       Params(30, "RecordLib" ) },
        { "Open",      Params(40, "ViewLib"   ) },
        { "Close",     Params(50, "EditLib"   ) },
        { "Inventory", Params(60, "ControlLib") },
        { "Report",    Params(70, "ReportLib" ) }
    };

    for (const auto& pair : options)
    {
        std::cout << "Entry: " << pair.first << " ==> { " << pair.second.moduleName << "    }" << std::endl;
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

然而,原始代码应该可以工作,并且显然是微软承认的错误。