I am changing to a new computer (windows), to which I pulled my project which used to work on my old laptop from the git. Unfortunately, the std::clamp function is not working when I try to execute the code now, even after specifying -std=c++17 in the execution.
Background: I am working with C++ in Visual Studio code (cpp standard set to c++17), MinGW compiler. This produces the same error:
#include <iostream>
#include <cmath> // goniometry, sqrt
#include <algorithm> // clamp
int main()
{
std::cout << std::clamp(2, 5, 17) << "\n";
}
I compile using g++ main.cpp -o main.exe -std=c++17
The error I get when running this is
PS C:\Users\Veren\OneDrive\Documents\Personal\Uni\Bsc3\BEP\Starting C++> g++ -std=c++17 main.cpp -o main.exe
main.cpp: In function 'int main()':
main.cpp:7:18: error: 'clamp' is not a member of 'std'
std::cout << std::clamp(2, 5, 17) << "\n";
I also checked and my vscode has c++17 as a the cpp standard setting. Usually I would expect this error when compiling with an older c++ version, but I am not sure whether that is the issue now given I am explicitely telling it to use c++17. What could be other reasons for this error? Or is it possible it's not actually using c++17, and if so, what else should i do for this version to be used?