为什么GCC 6.3在没有明确的C ++ 11支持的情况下编译这个Braced-Init-List代码? [英] Why does GCC 6.3 compile this Braced-Init-List code without explicit C++11 support?
问题描述
我对花括号列表的不同含义有疑问。
我知道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}};
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屋!