Function template
s permit overloading of other functions with the same name, and calling them works via ADL. Generic lambdas are objects with an overloaded ()
, so neither works.
You can pass a function overload set to an object pretty easily:
struct foo_overload_set_t {
template<class...Ts>
constexpr auto operator()(Ts&&...ts)const{ return foo(std::forward<Ts>(ts)...); }
};
which with RVO can be optimized away completely (zero overhead), and an instance of the entire overload set can be passed to an algorithm. You can also do this with a lambda at point of use, which can be generated by a macro.
With a bit more boilerplate the above overload set can also support conversion to any call-compatible function pointer, which neither the template
nor lambda solution supports (lambda requires signatures match one version, not compatibility).