A general object counter with CRTP idiom