为什么我无法编译结构化绑定?
Why can't I compile structured bindings?
我正在尝试编译此代码(在文件测试中.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
相关文章:
- 在基于范围的for循环中使用结构化绑定声明
- 使用结构化绑定'Reflection'
- 为什么结构化绑定不使用"auto&"返回对结构成员的引用,而是返回成员本身
- 为什么 boost::comb 对结构化绑定的支持缺少结构化绑定机制对 boost::tuples::cons 的适应?
- 结构化绑定初始值设定项表单 { 赋值表达式 } 对于 clang 上的数组类型失败
- 在 C++14 中手动实现结构化绑定
- 为什么结构化绑定不支持可变数组?
- 在只读(即 const)访问器上执行结构化绑定的最佳实践是什么?
- 带有 std::minmax 和 rvalues 的结构化绑定
- 在无序映射的结构化绑定中推导类型
- 为什么基于范围的 for 循环中的结构化绑定只是一个副本而不是引用?
- 您自己的类型的结构化绑定,不是结构或元组(通过公共成员函数)
- 结构化绑定:遍历元组的双端面
- 结构化绑定是否适用于 std::vector?
- 结构化绑定,无需复制即可获取子向量的连续元素
- 成员变量的结构化绑定
- 结构化绑定语法是否可以在多态 lambda 中使用
- 结构化绑定的用例是什么?
- C++ 有关unordered_map的结构化绑定问题
- 结构化绑定是否可重用?