Mojomoko
Mojomoko

Reputation: 529

Why can't I compile structured bindings?

I was trying to compile this code (in the file test.cpp)

#include<tuple>

int main(){
  auto [c,d] = make_tuple(3.1,2.3);
}

using g++ -std=c++17 test.cpp -o test , as well as clang++ -std=c++1z test.cpp -o test both would print the error message:

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);

using g++ (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 and clang version 3.8.0-2ubuntu4 (using Ubuntu 16.04.09) What am I missing?

Upvotes: 3

Views: 1358

Answers (1)

Abhishek Keshri
Abhishek Keshri

Reputation: 3244

From the official website of GCC:

  • Structured bindings is supported in gcc version 7

From the official website of clang:

  • Structured bindings is supported in version 4.

The following link presents compiler support for new C++ features. https://en.cppreference.com/w/cpp/compiler_support

Upvotes: 11

Related Questions