Advertisement
Guest User

Check that class default and copy constructable

a guest
Jan 28th, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. template <typename T>
  6. struct _check_default_and_copy_constructable
  7. {
  8.     _check_default_and_copy_constructable()
  9.     {
  10.         T value1;
  11.         volatile T value2(value1);
  12.     }
  13. };
  14.  
  15. #define check_default_and_copy_constructable(clazz) {_check_default_and_copy_constructable<clazz> _check;}
  16.  
  17. class default_constructable_and_copy_constructable
  18. {};
  19.  
  20. class non_default_constructable
  21. {
  22. public:
  23.     non_default_constructable(int a)
  24.     {
  25.         cout << a;
  26.     }
  27. };
  28.  
  29. class non_copy_constructable
  30. {
  31. public:
  32.     non_copy_constructable()
  33.     {}
  34.  
  35. private:
  36.     non_copy_constructable(const non_copy_constructable&);
  37. };
  38.  
  39. int main()
  40. {
  41.     check_default_and_copy_constructable(default_constructable_and_copy_constructable);
  42.     check_default_and_copy_constructable(non_default_constructable);
  43.     check_default_and_copy_constructable(non_copy_constructable);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement