Original Post
Looking for some help from the compile time programming gurus here. Here i would like add_task to push the message on to the stack only if arg.id matches any of the int template parameters. I.E abc.add_task() will push only timer_msg, update_msg and will just ignore all other messages. Just wondering if there is any possible way i can do this through template machinery instead of maintaing a runtime checks.
const int no_msg = 0;
// .. other message IDs
template
<
int arg1 = no_msg,
int arg2 = no_msg,
int arg3 = no_msg,
int arg4 = no_msg
/// + arbitrary more ids
>
class message_center_
{
public:
explicit message_center_(std::stack<message>& arg) : ref(arg) {}
void add_task (const message& arg)
{
ref.push(arg);
}
private:
std::stack<message>& ref;
};
message_center_<timer_msg, update_msg\> abc;
// sorry don't know how to display <,> without source tags here