为什么GCC 6.3在没有明确的C ++ 11支持的情况下编译这个Braced-Init-List代码? [英] Why does GCC 6.3 compile this Braced-Init-List code without explicit C++11 support?

查看:269
本文介绍了为什么GCC 6.3在没有明确的C ++ 11支持的情况下编译这个Braced-Init-List代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对花括号列表的不同含义有疑问。



我知道C ++ 03不支持C ++ 11的 initializer_list 。然而,即使没有 -std = c ++ 11 编译器标志,gcc 6.3 会正确初始化 interpolate 这个代码:

  map< string,string> interpolate = {{F,a& b& c},{H,p ^ 2 + w},{K,H> 10 || e < 5},{J,F&&!K}}; 

我被问及为什么这会起作用,并且我意识到我没有答案。这是一个Brace-Init-List,但是我们从初始化标准容器的方式通常是通过 initializer_list 。那么非C ++ 11代码将如何完成初始化? 解决方案

gcc 6.x的默认编译器命令是 -std = gnu ++ 14 ,因此编译器会使用更高版本的C ++语言标准隐式编译您的代码。

如果你想用C ++编译,你需要手动指定 -std = c ++ 03 03。


I have a question about the different meanings of a curly-brace enclosed list.

I know that C++03 did not support C++11's initializer_list. Yet, even without the -std=c++11 compiler flag, gcc 6.3 will properly initialize interpolate with this code:

map<string, string> interpolate = { { "F", "a && b && c" }, { "H", "p ^ 2 + w" }, { "K", "H > 10 || e < 5" }, { "J", "F && !K" } };

I was challenged on why this would work, and I realized I didn't have an answer. This is a Brace-Init-List, but the way we get from that to initializing a standard container is typically through an initializer_list. So how would non-C++11 code be accomplishing the initialization?

解决方案

The default compiler command for gcc 6.x is -std=gnu++14, so the compiler is implicitly compiling your code using a later version of the C++ language standard.

You will need to manually specify -std=c++03 if you want to compile in C++03.

这篇关于为什么GCC 6.3在没有明确的C ++ 11支持的情况下编译这个Braced-Init-List代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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