/* The following code example is taken from the book* "C + + templates-the Complete Guide" * by David Vandevoorde and Nicol Ai M. Josuttis, Addison-wesley, 2002** (C) Copyright David Vandevoorde and Nicolai M. josuttis 2002.* Permission to copy, Use, modify, sell and distribute this software* are granted provided this copyright notice appears in all copies.* this SOF Tware is provided ' as is ' without express or implied* warranty, and with no claim as to it suitability for any purpose.*/ #include <iostream>template<typename t>class isclasst {private:typedef char one;typedef struct {char a[2];} Two;template<typename c> static one test (int C::*), template<typename c> static, test (...); public:enum {Yes = sizeof (test<t> (0)) = = 1};enum {No =! Yes};}; Class MyClass {};struct mystruct {};union myunion {};void myfunc () {}enum E {e1} e;//check by passing type as template a Rgumenttemplate <typename t>void Check () {if (Isclasst<t>::yes) {Std::cout << "isclasst" << Std::endl;} else {std::cout << "! Isclasst "<< Std::endl;}} Check by passing type as function call Argumenttemplate <typename t>void checkt (T) {check<t> ();} int main () {std::cout << "int:";check<int> (); Std::cout << "MyClass:";check<myclass> (); std::c Out << "MyStruct:"; MyStruct S;checkt (s); Std::cout << "myunion:";check<myunion> (); Std::cout << "enum:"; Checkt (e); std: : cout << "MyFunc ():"; Checkt (MyFunc);}
C + + template determines whether the class type