I\'ve just got confused how to implement something in a generic way in C++. It\'s a bit convoluted, so let me explain step by step.
Consider such code:
With generic lambda from C++14 you might do:
template void a(T t) { /* do something */}
template void b(T t) { /* something else */ }
template
void function(F&& f) {
f(someobj);
f(someotherobj);
}
void test() {
// For simple cases, auto&& is even probably auto or const auto&
function([](auto&& t){ a(t); });
function([](auto&& t){ b(t); });
// For perfect forwarding
function([](auto&& t){ a(std::forward(t)); });
function([](auto&& t){ b(std::forward(t)); });
}
Can compilers still inline the calls if they are made via function pointers?
They can, but it is indeed more complicated, and they may fail more often than with functor or template.