在 VS 2013 中使用初始化列表初始化地图映射 [英] Initializing map of maps with initializer list in VS 2013

查看:43
本文介绍了在 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 中使用初始化列表初始化地图映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆