#include <iostream>
#include <unordered_set>
#include <memory>
template < typename T, typename TAG = void > struct magic
{
// ...
/* private: */ static std::unordered_set<T*> objects ;
};
template < typename T, typename TAG > std::unordered_set<T*> magic<T,TAG>::objects ;
template < typename T, typename TAG = void > struct tracked
: T, magic< tracked<T,TAG>, TAG >
{
template < typename ... ARGS > tracked( ARGS... args ) : T(args...) {}
};
struct A { /* ... */ };
template < int N > struct use_case {} ;
int main()
{
std::cout << std::addressof( tracked<A>::objects ) << '\n' ;
std::cout << std::addressof( tracked< A, use_case<1> >::objects ) << '\n' ;
std::cout << std::addressof( tracked< A, use_case<2> >::objects ) << '\n' ;
std::cout << std::addressof( tracked< A, use_case<3> >::objects ) << '\n' ;
std::cout << std::addressof( tracked< A, use_case<4> >::objects ) << '\n' ;
std::cout << std::addressof( tracked< A, use_case<5> >::objects ) << '\n' ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dW5vcmRlcmVkX3NldD4KI2luY2x1ZGUgPG1lbW9yeT4KCnRlbXBsYXRlIDwgdHlwZW5hbWUgVCwgdHlwZW5hbWUgVEFHID0gdm9pZCAgPiBzdHJ1Y3QgbWFnaWMKewogICAgLy8gLi4uCiAgICAvKiBwcml2YXRlOiAqLyBzdGF0aWMgc3RkOjp1bm9yZGVyZWRfc2V0PFQqPiBvYmplY3RzIDsKfTsKCnRlbXBsYXRlIDwgdHlwZW5hbWUgVCwgdHlwZW5hbWUgVEFHID4gc3RkOjp1bm9yZGVyZWRfc2V0PFQqPiBtYWdpYzxULFRBRz46Om9iamVjdHMgOwoKdGVtcGxhdGUgPCB0eXBlbmFtZSBULCB0eXBlbmFtZSBUQUcgPSB2b2lkID4gc3RydWN0IHRyYWNrZWQKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDogVCwgbWFnaWM8IHRyYWNrZWQ8VCxUQUc+LCBUQUcgPgp7CiAgICB0ZW1wbGF0ZSA8IHR5cGVuYW1lIC4uLiBBUkd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