I noticed the following line in the open-source project FeatherKit:
int _[] = { (SubscribeToType<MessageTypes>( bus, receiver, desubscribers, unsubscribe ), 0)... };
With the following context:
template<class... MessageTypes>
void Subscribe( MessageBus& bus, MessageReceiver<MessageTypes...>& receiver, bool unsubscribe ) {
std::vector<std::function<void()>> desubscribers;
int _[] = { (SubscribeToType<MessageTypes>( bus, receiver, desubscribers, unsubscribe ), 0)... };
(void) _;
receiver.desubscribers = desubscribers;
}
It's obviously executing the function SubscribeToType for each parameter in the variadic template.
My question is twofold:
How, exactly, does the line work? How come parameter unpacking is allowing that function to execute for each parameter in the variadic template?
I am very certain this line could be replaced by a lambda. How could you replace the line with a lambda expression?
I've contacted the original author of FeatherKit, but he wasn't able to answer my question at that time.