With template meta-programming it's possible to query properties of types. For example in the case below I'm checking if a certain type has a member function "foo" which takes in another type as the argument.
Is there a way to check if the parameter type is an exact match for the template vs. one that be converted to it, e.g. double or char can be converted into float (causing main to print true twice) but I'm trying to see if there is a way to structure my_test_t so that it matches perfectly, i.e. main() prints false unless T2 = float.
struct S2
{
int foo(float x)
{
return 0;
}
};
template <typename T1, typename T2>
using my_test_t = decltype(declval<T1>().foo(declval<T2>()));
template <typename T1, typename T2, typename = void>
struct is_formed : std::false_type
{
};
template <typename T1, typename T2>
struct is_formed<T1, T2, void_t<my_test_t<T1, T2>>> : std::true_type
{
};
int main()
{
cout << boolalpha << is_formed<S2, double>::value << endl;
cout << boolalpha << is_formed<S2, char>::value << endl;
}