Since C++14 we can use generic lambdas:
auto generic_lambda = [] (auto param) {};
This basically means that its call operator is templated
Consider this
#include
namespace {
auto out_ = [] ( const auto & val_)
{
std::cout << val_;
return out_ ;
};
auto print = [](auto first_param, auto... params)
{
out_(first_param);
// if there are more params
if constexpr (sizeof...(params) > 0) {
// recurse
print(params...);
}
return print;
};
}
int main()
{
print("Hello ")("from ")("GCC ")(__VERSION__)(" !");
}
(wandbox here) This "print" lambda is:
And no templates in sight. (just underneath :) ) No C++ code that looks like radio noise. Simple, clean and most importantly:
No wonder "it feels like a new language".