I want to write an unmarshaller to extract arguments stored in a msgpack array for individual arguments to a call of sigc::signal::emit(...)
. I tried this:
I have always felt that the most maintainable way to specialise a member function is to defer to a specialised function object:
#include
struct object_array
{
};
template
struct implement_do_emit
{
template
void operator ()(This *that, const object_array& arg) const;
};
template
struct MsgpackAdapter
{
friend class implement_do_emit;
virtual void do_emit(const object_array& mp_args)
{
auto impl = implement_do_emit();
impl(this, mp_args);
}
};
template
struct implement_do_emit
{
template
void operator ()(This *that, const object_array& arg) const
{
std::cout << "one type version\n";
}
};
template
struct implement_do_emit
{
template
void operator ()(This *that, const object_array& arg) const
{
std::cout << "two type version\n";
}
};
int main()
{
MsgpackAdapter pi {};
pi.do_emit(object_array());
MsgpackAdapter pii {};
pii.do_emit(object_array());
}