I'm trying to create a proxy class for a function which takes Message as parameter.
template<typename MsgType>
using SendFunctor = void(*)(MsgType&);
struct Message {};
template<typename T>
struct Test {
Test(T t) {
Message msg;
t(msg);
}
};
template<typename MsgType>
Test(SendFunctor<MsgType>) -> Test<SendFunctor<MsgType>>;
Inside main then I simply declare a variable and everything works fine both with free functions and lambda
Test test([](Message&) { std::cout << "Hello2" << std::endl; });
However, after adding another template parameter to Test and modifying the deduction guide
template<typename MsgType, typename T>
struct Test {
Test(T t) {
Message msg;
t(msg);
}
};
template<typename MsgType>
Test(SendFunctor<MsgType>) -> Test<Message, SendFunctor<MsgType>>;
// or what I really want to achieve
// template<typename MsgType>
// Test(SendFunctor<MsgType>) -> Test<MsgType, SendFunctor<MsgType>>;
I got an error class template argument deduction failed. In fact, everything works fine if I pass a free function to the constructor.
Can someone please explain to me, why lambda here breaks the entire deduction? And how can I fix this?