Advertisement
Guest User

Untitled

a guest
Oct 10th, 2015
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.49 KB | None | 0 0
  1. #include <type_traits>
  2.  
  3. struct default_constructible {};
  4.  
  5. struct not_constructible {
  6.     not_constructible() = delete;
  7. };
  8.  
  9. struct implicitly_constructible_from_int {
  10.     implicitly_constructible_from_int(int) {}
  11. };
  12.  
  13. struct explicitly_constructible_from_int {
  14.     explicit explicitly_constructible_from_int(int) {}
  15. };
  16.  
  17. struct explicitly_convertible_to_int {
  18.     explicit operator int() const {return 0;}
  19. };
  20.  
  21. class private_default_constructible {
  22.     private_default_constructible() {}
  23. };
  24.  
  25. struct protected_default_constructible {
  26. protected:
  27.     protected_default_constructible() {}
  28. };
  29.  
  30. //TODO: SFINAE
  31.  
  32. static_assert(std::is_constructible_v<int>);
  33. static_assert(std::is_constructible_v<int, int>);
  34. static_assert(std::is_constructible_v<default_constructible>);
  35. static_assert(std::is_constructible_v<implicitly_constructible_from_int, int>);
  36. static_assert(std::is_constructible_v<explicitly_constructible_from_int, int>);
  37. static_assert(std::is_constructible_v<implicitly_constructible_from_int, double>);
  38. static_assert(std::is_constructible_v<explicitly_constructible_from_int, double>);
  39. static_assert(std::is_constructible_v<int[5]>);
  40. static_assert(std::is_constructible_v<int&, int&>);
  41. static_assert(std::is_constructible_v<const int&, int>);
  42. static_assert(std::is_constructible_v<int&&, int>);
  43.  
  44. static_assert(std::is_constructible_v<const default_constructible>);
  45. static_assert(std::is_constructible_v<volatile default_constructible>);
  46. static_assert(std::is_constructible_v<const volatile default_constructible>);
  47.  
  48. static_assert(not std::is_constructible_v<not_constructible>);
  49. static_assert(not std::is_constructible_v<void>);
  50. static_assert(not std::is_constructible_v<void, int>);
  51. static_assert(not std::is_constructible_v<void, void>);
  52. static_assert(not std::is_constructible_v<default_constructible, void>);
  53. static_assert(not std::is_constructible_v<int[]>);
  54. static_assert(not std::is_constructible_v<explicitly_constructible_from_int, explicitly_convertible_to_int>);
  55. static_assert(not std::is_constructible_v<private_default_constructible>);
  56. static_assert(not std::is_constructible_v<not_constructible[5]>);
  57. static_assert(not std::is_constructible_v<int[5], int>);
  58. static_assert(not std::is_constructible_v<int[5], int[5]>);
  59. static_assert(not std::is_constructible_v<void()>);
  60. static_assert(not std::is_constructible_v<void(), void()>);
  61.  
  62. struct protected_test : protected_default_constructible {
  63.     static_assert(not std::is_constructible_v<protected_default_constructible>);
  64. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement