fork download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. class A // trivial
  5. {
  6. int dummy;
  7. public:
  8.  
  9. void* operator new[](std::size_t size)
  10. {
  11. std::cout << "A::new[] size = " << size << '\n';
  12.  
  13. return ::operator new[](size);
  14. }
  15. };
  16.  
  17. class B // nicht trivial
  18. {
  19. int dummy;
  20. public:
  21.  
  22. ~B() { dummy = 0; }
  23.  
  24. void* operator new[](std::size_t size)
  25. {
  26. std::cout << "B::new[] size = " << size << '\n';
  27.  
  28. return ::operator new[](size);
  29. }
  30. };
  31.  
  32. int main()
  33. {
  34. using namespace std;
  35.  
  36. A* a = new A[10];
  37. B* b = new B[10];
  38.  
  39. cout << "is_trivially_destructible<A>::value = " << is_trivially_destructible<A>::value << '\n';
  40. cout << "is_trivially_destructible<B>::value = " << is_trivially_destructible<B>::value << '\n';
  41.  
  42. delete[] b;
  43. delete[] a;
  44.  
  45. return 0;
  46. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
A::new[] size = 40
B::new[] size = 44
is_trivially_destructible<A>::value = 1
is_trivially_destructible<B>::value = 0