#include <type_traits>
#include <utility>
#include <iostream>
template <typename T, typename = void>
struct foo_impl {};
template <typename T>
inline auto foo(T x) -> decltype(foo_impl<T>{}(x))
{
return foo_impl<T>{}(x);
}
template <typename T>
struct foo_impl<T,typename std::enable_if<std::is_integral<T>::value>::type>
{
void operator()(T) {}
};
template <typename T>
struct has_foo
{
struct yes {};
struct no {};
template <typename T1>
static auto test(T1 x) -> decltype(foo(x),void(),yes{});
static no test(...);
static const bool value = std::is_same<yes,decltype(test(std::declval<T>()))>::value;
};
template <typename T>
struct foo_impl<T,typename std::enable_if<has_foo<unsigned>::value && std::is_floating_point<T>::value>::type>
{
void operator()(T) {}
};
int main()
{
std::cout << has_foo<float>::value << '\n';
std::cout << has_foo<int>::value << '\n';
foo(3.1);
}
I2luY2x1ZGUgPHR5cGVfdHJhaXRzPgojaW5jbHVkZSA8dXRpbGl0eT4KI2luY2x1ZGUgPGlvc3RyZWFtPgoKdGVtcGxhdGUgPHR5cGVuYW1lIFQsIHR5cGVuYW1lID0gdm9pZD4Kc3RydWN0IGZvb19pbXBsIHt9OwoKdGVtcGxhdGUgPHR5cGVuYW1lIFQ+CmlubGluZSBhdXRvIGZvbyhUIHgpIC0+IGRlY2x0eXBlKGZvb19pbXBsPFQ+e30oeCkpCnsKICAgICAgICByZXR1cm4gZm9vX2ltcGw8VD57fSh4KTsKfQoKdGVtcGxhdGUgPHR5cGVuYW1lIFQ+CnN0cnVjdCBmb29faW1wbDxULHR5cGVuYW1lIHN0ZDo6ZW5hYmxlX2lmPHN0ZDo6aXNfaW50ZWdyYWw8VD46OnZhbHVlPjo6dHlwZT4KewogICAgICAgIHZvaWQgb3BlcmF0b3IoKShUKSB7fQp9OwoKdGVtcGxhdGUgPHR5cGVuYW1lIFQ+CnN0cnVjdCBoYXNfZm9vCnsKICAgICAgICBzdHJ1Y3QgeWVzIHt9OwogICAgICAgIHN0cnVjdCBubyB7fTsKICAgICAgICB0ZW1wbGF0ZSA8dHlwZW5hbWUgVDE+CiAgIC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