为什么我无法编译结构化绑定?

Why can't I compile structured bindings?

本文关键字:结构化 绑定 编译 为什么      更新时间:2023-10-16

我正在尝试编译此代码(在文件测试中.cpp(

#include<tuple>
int main(){
  auto [c,d] = make_tuple(3.1,2.3);
}

g++ -std=c++17 test.cpp -o test,以及 clang++ -std=c++1z test.cpp -o test两者都会打印错误消息:

test.cpp: In function ‘int main()’:
test.cpp:3:7: error: expected unqualified-id before ‘[’ token
auto [c,d] = make_tuple(3.1,2.3);

用g++ (Ubuntu 5.4.0-6ubuntu1~16.04.9( 5.4.0 20160609和CLANG 版本 3.8.0-2Ubuntu4(使用 Ubuntu 16.04.09(我错过了什么?

来自GCC的官方网站:

  • gcc 版本 7 支持结构化绑定

来自clang的官方网站:

  • 版本 4 支持结构化绑定。

以下链接提供了编译器对新功能C++的支持。 https://en.cppreference.com/w/cpp/compiler_support