简体   繁体   中英

std::gcd does not compile in g++ 5.4.0 — 'gcd' is not a member of 'std'

Environment:

  • Ubuntu 16.04 64 bit
  • g++ version 5.4.0

This is the code:

#include <numeric>
...
auto g = std::gcd(10, 4);
...

I have turned on the -std=c++17 option in the compiling command:

g++ -m64 -std=c++17   -c -g -w -MMD -MP -MF "build/Debug/GNU-Linux/main.o.d" -o build/Debug/GNU-Linux/main.o main.cpp

Then I got the error:

error: 'gcd' is not a member of 'std'

From this webpage , std::gcd is introduced since C++17.

From this webpage , my version of g++ supports C++17.

But why is there still an error? The same code compiles without any error in Visual Studio 2017.

std::gcd is available from GCC 7.1 onwards only.

From Table 1.5. C++ 2017 Implementation Status

在此处输入图片说明

See conformance viewer for multiple GCC versions .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM