Jan 28, 2016 at 7:18pm UTC
Hi,
I wanted to create a template lambda so that I do not have to re-define this behaviour for each possible type.. like so:
///// want to avoid this:
auto loggerDeleterWidget = [] (Widget * p ) {
std::cout << p << std::endl;
delete p;
};
auto loggerDeleterDoc = [] (Doc * p ) {
std::cout << p << std::endl;
delete p;
};
//////////
However the following does not compile:
template<typename T>
auto loggerDeleter = [] (T * p ) {
std::cout << p << std::endl;
delete p;
};
Any suggestions as to how to go about this?
Regards,
Juan
Jan 28, 2016 at 7:32pm UTC
Why lambda? Can't you just make it a regular function template?
Jan 28, 2016 at 8:15pm UTC
Ok, yes I know I can use a function object... but, I wanted to see how far i could go with lamas. The polymorphic lambda suggested by Cubby seems what I was looking for..
Thanks to both of you!!
Juan