I am getting expected primary expression before constexpr in codeblocks only. Is there a way to fix this? This is the code I am trying to test. I have set c++ 17 as the compiler. I am using GNU GCC Compiler. GCC (MinGW.org GCC-6.3.0-1) 6.3.0. I am not getting this error in Visual Studio.
#include <iostream>
#include <vector>
template<class T>
void testType(std::vector<T> &x)
{
if constexpr (std::is_same_v<T, std::string>)
{
//push string
std::cout<<"String\n";
}
else if constexpr (std::is_same_v<T,int>)
{
//push integer
std::cout<<"int\n";
}
}
int main()
{
std::vector<std::string> x;
testType(x);
return 0;
}
This is the error I am getting.
error: expected primary-expression before 'constexpr'
error: expected ')' before 'constexpr'