Guest User

Untitled

a guest
Jun 20th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. /**
  2. isAbstract<T>::result is 1 if T is abstract, 0 if otherwise.
  3. */
  4. template<typename T>
  5. class isAbstract
  6. {
  7. class No { };
  8. class Yes { No no[3]; };
  9.  
  10. template<class U> static No test( U (*)[1] ); // not defined
  11. template<class U> static Yes test( ... ); // not defined
  12.  
  13. public:
  14. enum { result = sizeof( isAbstract<T>::template test<T>( 0 ) ) == sizeof(Yes) };
  15. };
  16.  
  17. bool twoAbstract = isAbstract<myClass2>::result;
  18. bool oneAbstract = isAbstract<myClass1>::result;
  19.  
  20. error C2784: 'AiLive::isAbstract<T>::No AiLive::isAbstract<T>::test(U (*)[1])' : could not deduce template argument for 'U (*)[1]' from 'myClass2'
  21.  
  22. template<class U> static No test( U (*)[1] );
  23.  
  24. template<class U> static No test( U (*x)[1] );
  25. template<class U> static No test( U (*)() );
  26. template<class U> static No test( U (*x)() );
  27.  
  28. template <typename U>
  29. struct U2 : public U
  30. {
  31. U2( U* ) {}
  32. };
  33.  
  34. // Match if I can make a U2
  35. template <typename U> static No test( U2<U> x );
  36.  
  37. // Match if I can make a U2
  38. template <typename U> static No test( U2<T> x );
  39.  
  40. template<typename T>
  41. class isAbstract
  42. {
  43. class No { };
  44. class Yes { No no[3]; };
  45.  
  46. template<class U> static No test( U (*)[1] ); // not defined
  47. template<class U> static Yes test( ... ); // not defined
  48.  
  49. public:
  50. enum { result = sizeof( test<T>( 0 ) ) == sizeof(Yes) };
  51. };
  52.  
  53. template< typename T, typename U>
  54. class isAbstract
  55. {
  56. class No { };
  57. class Yes { No no[3]; };
  58.  
  59. template<class U> static No test( U (*)[1] ); // not defined
  60. template<class U> static Yes test( ... ); // not defined
  61.  
  62. public:
  63. enum { result = sizeof( isAbstract<T>::template test<T>( 0 ) ) == sizeof(Yes) };
  64. };
  65.  
  66.  
  67. bool twoAbstract = isAbstract<myClass2, SomeTypeU>::result;
Add Comment
Please, Sign In to add comment