You can have the best of both worlds
template<class F>
class MsgProcessorT:public IMsgProcessor{
F f_;
public:
MsgProcessorT(F f):f_(f){}
virtual void handle_msg(const Message& msg) {
f_(msg);
}
};
template<class F>
IMsgProcessor* CreateMessageProcessor(F f){
return new MsgProcessor<T>(f);
};
Then you can either use like this
Socket s(CreateMessageProcessor([](const Message& msg){...}));
Or to make it even easier add another constructor to Socket
class Socket{
...
template<class F>
Socket(F f):processor_(CreateMessageProcessor(f){}
};
Then you could do
Socket s([](const Message& msg){...});
And still have the same efficiency as a virtual function call