template< typename ... Args >
class Message {
public:
Message( Args&& ... args ) {
mArgs = std::make_tuple( args ... );
}
std::tuple< Args ... > mArgs;
typedef std::function< void ( Args ... ) > HandlerType;
void Consume( HandlerType handler ) {
// handler( mArgs );
// How does one unpack this?
}
};
// Testing code
Message<int, int> msg(1, 2);
msg.Consume( [] ( int i, int j ) {
std::cout << i << ',' << j << '\n';
});
I'm attempting a simple message passing API, trying to provide a simple templated interface for messages and arguments. I'm running into an issue when I want to pass the arguments into a function.
I've not used variadic templates too much, and was wondering if there is an elegant solution to my problem.