fork download
  1. #include <iostream>
  2. #include <unordered_set>
  3. #include <memory>
  4.  
  5. template < typename T, typename TAG = void > struct magic
  6. {
  7. // ...
  8. /* private: */ static std::unordered_set<T*> objects ;
  9. };
  10.  
  11. template < typename T, typename TAG > std::unordered_set<T*> magic<T,TAG>::objects ;
  12.  
  13. template < typename T, typename TAG = void > struct tracked
  14. : T, magic< tracked<T,TAG>, TAG >
  15. {
  16. template < typename ... ARGS > tracked( ARGS... args ) : T(args...) {}
  17. };
  18.  
  19. struct A { /* ... */ };
  20.  
  21. template < int N > struct use_case {} ;
  22.  
  23. int main()
  24. {
  25. std::cout << std::addressof( tracked<A>::objects ) << '\n' ;
  26. std::cout << std::addressof( tracked< A, use_case<1> >::objects ) << '\n' ;
  27. std::cout << std::addressof( tracked< A, use_case<2> >::objects ) << '\n' ;
  28. std::cout << std::addressof( tracked< A, use_case<3> >::objects ) << '\n' ;
  29. std::cout << std::addressof( tracked< A, use_case<4> >::objects ) << '\n' ;
  30. std::cout << std::addressof( tracked< A, use_case<5> >::objects ) << '\n' ;
  31. }
  32.  
Success #stdin #stdout 0s 2992KB
stdin
Standard input is empty
stdout
0x804b700
0x804b720
0x804b740
0x804b760
0x804b780
0x804b7a0