#include <iostream>
#include <vector>

struct X{

    static std::vector<X*>& getRegistry(){
         static std::vector<X*> registry;
         return registry;
    }

    X(){
        getRegistry().push_back(this); // Each X adds itself to the registry
    }
};

template<typename T>
struct Y : X{ 
private:   
   static T instance; // The per-type singleton
};

template<typename T>
T Y<T>::instance {};

struct A : Y<A>{};
struct B : Y<B>{};
struct C : Y<C>{};

int main(){
	std::cout << "Number of objects in the registry: " << X::getRegistry().size() << std::endl;	
}
