I have test code as below.
#include <iostream>
#include <vector>
using namespace std;
template<typename Cont>
class Test
{
template<typename T, typename = void> static constexpr bool check = false;
template<typename T>
static constexpr bool check<T, std::void_t<typename T::iterator>> = true;
public:
static bool fun()
{
return check<Cont>;
}
};
int main([[maybe_unused]] int argc, [[maybe_unused]] char *argv[])
{
cout << Test<vector<int>>::fun() << endl;
cout << Test<int>::fun() << endl;
return 0;
}
Compile with g++, compiler will complain:
test.cpp:12:27: error: explicit template argument list not allowed
12 | static constexpr bool check<T, std::void_t<typename T::iterator>> = true;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
But the clang++ compiles the code without any error.
What does the error g++ thorws mean? How can I modify the code that both g++ and clang++ compiles it?
Thanks!