template<class T, class U> struct is_same { enum { value = false }; };
template<class T> struct is_same<T, T> { enum { value = true }; };
namespace test_sfinae_and_delete {
namespace ns1 {
template<class T> double f(T) = delete; char f(...);
static_assert(is_same<decltype(f(3)),char>::value, "");
template<class T> decltype(f(T{})) g(T); template<class T> int *g(T);
void foo() {
int *ip = g(3);
}
}
namespace ns2 {
template<class T> double* f(T);
template<> double* f(double) = delete;
template<class T> decltype(f(T{})) g(T); template<class T> int *g(T); void foo() {
double *dp = g(3); int *ip = g(3.14); }
}
namespace ns3 {
template<class T> double* f(T) = delete;
template<> double* f(double);
template<class T> decltype(f(T{})) g(T); template<class T> int *g(T);
void foo() {
int *dp = g(3); double *ip = g(3.14); }
} }
namespace test_explicit_specialization_of_member {
namespace ns1 {
template<class T> struct X {
int* f(T) = delete;
};
template<> int* X<int>::f(int) { }
template<class T> decltype(X<T>{}.f(T{})) g(T); template<class T> int *g(T);
void foo() {
int *ip2 = g(3.14); int *ip = g(3); }
}
namespace ns2 {
struct X {
template<class T> double* f(T) = delete;
};
template<> double* X::f(int);
template<class T> decltype(X{}.f(T{})) g(T); template<class T> int *g(T);
void foo() {
int *ip2 = g(3.14); int *ip = g(3); }
}
namespace ns3 {
template<class T> struct X {
template<class U> double *f1(U, T) = delete;
template<class U> double *f2(U, T) = delete;
};
template<> template<> double* X<int>::f1(int, int);
template<> template<class U> double* X<int>::f2(U, int);
template<class T, class U> decltype(X<T>{}.f1(U{}, T{})) g1(U, T); template<class T, class U> int *g1(U, T);
template<class T, class U> decltype(X<T>{}.f2(U{}, T{})) g2(U, T); template<class T, class U> int *g2(U, T);
void foo() {
int *ip2 = g1(3.14, 3); int *ip = g1(3, 3); {
int *ip3 = g2(3.14, 3); int *ip4 = g2(3, 3); }
{
int *ip3 = g2(3.14, 3.14);
int *ip4 = g2(3, 3.14);
}
}
}
namespace ns4 {
template < typename T> T* foo (T);
template <> int* foo(int) = delete;
template <> int* foo(int);
int *IP = foo(2); double *DP = foo(3.14);
}
namespace ns5 {
template < typename T> T* foo (T);
template <> int* foo(int); template <> int* foo(int) = delete;
}
}