#include <iostream>
#include <unordered_set>

struct A
{
    A() { objects.insert(this) ; /* ... */ }
    A( const A& ) : A() { /* ... */ }
    A( A&& ) : A() { /* ... */ }
    ~A() { /* ... */ objects.erase(this) ; }

    template< typename FN > static void for_each_instance( FN fn )
    { for( A* p : objects ) fn(p) ; }

    void foo( int i, char c )
    { std::cout << "A::foo( " << this << ", " << i << ", " << c << " )\n" ; }

    void bar( double d ) const { std::cout << "A::bar( " << d << " )\n" ; }

    static std::unordered_set<A*> objects ;
};

std::unordered_set<A*> A::objects ;

int main()
{
    std::size_t n ;
    std::cout << "how many? " && std::cin >> n ;
    while( n-- ) new A() ;

    A::for_each_instance( []( A* p ) { p->foo( 99, 'X' ) ; } ) ;
    A::for_each_instance( []( A* p ) { p->bar( 12.8 ) ; } ) ;
    A::for_each_instance( []( A* p ) { delete p ; } ) ;
}
