//////////////////////////////////////// // test1 -- re-implementation of // is_convertible and enable_if //////////////////////////////////////// #include using namespace std; struct yes {}; struct no { char _c[2]; }; struct any_conversion { template any_conversion(T const &); }; template struct checker { static no check(any_conversion); static yes check(T); }; template struct is_convertible { static From _from; static const bool value = sizeof(checker::check(_from)) == sizeof(yes); }; template struct enable_if {}; template <> struct enable_if { typedef void type; }; template struct disable_if { typedef void type; }; template <> struct disable_if {}; struct Foo { Foo() {}; Foo(Foo const & f) { cout << "Copy Constructor." << endl; } template Foo(T const & t, typename enable_if::value>::type * = 0) { cout << "Convertible." << endl; } template Foo(T const & t, typename disable_if::value>::type * = 0) { cout << "Not Convertible." << endl; } }; int main() { Foo f; Foo f2(f); Foo f3(1); return 0; }