I came across this question, where the answer describes nice detail about how can the generic lambda functions be used to replace the std::function
technique and how to rewire the stop condition to enable the return type deduction.
Based on the above I created the following working example:
#include <cstdio>
void printSeq(unsigned start) {
auto recursion = [](auto&& self, const char* format, unsigned current) {
printf(format, current);
if(!current)
return static_cast<void>(printf("\n"));
else
self(self, ", %u", current - 1);
};
recursion(recursion, "%u", start);
}
int main() {
return (printSeq(15), 0);
}
My question is that what's the advantage using auto&&
over the auto&
in this case? Should I use the std::move
here?