fork download
  1. #include <cstdio>
  2.  
  3. struct A
  4. {
  5. A()
  6. :
  7. dummy(printf("Starting to construct A()\n"))
  8. {
  9. printf("Fully constructed A()\n");
  10. }
  11. int dummy;
  12. };
  13.  
  14. template <typename T>
  15. struct Nesting;
  16.  
  17. template <>
  18. struct Nesting<int>
  19. {
  20. constexpr static int value = 0;
  21. };
  22.  
  23. template <template <typename> class T, typename I>
  24. struct Nesting<T<I>>
  25. {
  26. constexpr static int value = 1 + Nesting<I>::value;
  27. };
  28.  
  29. template<typename T>
  30. struct B
  31. {
  32. int dummy;
  33. A a;
  34. T b;
  35. B()
  36. :
  37. dummy(printf("Starting to construct B() with nesting %d\n", Nesting<B<T>>::value)),
  38. a(),
  39. b()
  40. {
  41. printf("Fully constructed B() with nesting %d\n", Nesting<B<T>>::value);
  42. }
  43. };
  44.  
  45. int main()
  46. {
  47. B<B<B<int>>> Test;
  48. return 0;
  49. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
Starting to construct B() with nesting 3
Starting to construct A()
Fully constructed A()
Starting to construct B() with nesting 2
Starting to construct A()
Fully constructed A()
Starting to construct B() with nesting 1
Starting to construct A()
Fully constructed A()
Fully constructed B() with nesting 1
Fully constructed B() with nesting 2
Fully constructed B() with nesting 3