Here's an extremely simple code:
#include <tuple>
#include <type_traits>
#include <array>
template <class T> struct TypeHolder {};
template<class T, size_t N>
constexpr size_t array_size(TypeHolder<std::array<T,N>>)
{
return N;
};
using AnyType = int;
template <class V, typename std::enable_if<std::is_same<V,
std::array<typename V::value_type, array_size(TypeHolder<V>())>>::value, AnyType>::type* = nullptr>
void test(V & v)
{
}
int main()
{
std::array<int, 5> x;
test(x);
}
Don't ask what the hell this code is for. It doesn't matter. It's just refined and simplified example of what I found. The important thing is it seems to be valid C++ 17 code anyway.
test()
is enabled (in further SFINAE situation) only when V is std::array
. Yeah, I know that I can just do template<class T, int N> void test(array<T, N>& v)
but this more dirty template parameters help me in some cases for not having int N
. (Trust me!)
Anyway this C++ 17 code fails to compile in Visual Studio 2019 with C++ 17 setup. However it works well in GCC and Clang.
Hours ago, I posted related question here. The only thing I could found in common is that they're about some complicated templates and that they result in same error codes :
error C2672: no matching overloaded function found
error C2783: could not deduce template argument for '__formal'
Questions are....
- Is that a valid C++ 17 code?
- Then why does MSVC fail to compile?
- What is the relation with my previous question?
- How should I deal with this if I decided to just use MSVC?