I want to check if a non-member function that accepts a T parameter type exists. To do so I used void_t
"trick" presented by Mr. Walter E. Brown at cppcon(same trick works without any problems to check if a member type or member function exists).
#include <iostream>
#include <type_traits>
template<typename...>
using void_t = void;
void Serialize(float&)
{
}
template<typename T, typename = void>
struct has_external_serialize : std::false_type
{
};
template<typename T>
struct has_external_serialize<T, void_t<decltype(Serialize(std::declval<T&>()))>> : std::true_type
{
};
void Serialize(int&)
{
}
int main(int argc, const char * argv[])
{
std::cout<<has_external_serialize<float>::value<<has_external_serialize<int>::value;
}
This code prints 11
when compiled using GCC and 10
when compiled with clang(xcode 5.1.1).
My questions is - is this code correct? If yes, is there a bug in clang or a bug in GCC or the code is in some "implementation defined" area and I can't assume it will have same behaviour on all platforms?