C++ auto Generic lambda (C++14)


Example

C++14

C++14 allows to use auto in lambda argument

auto print = [](const auto& arg) { std::cout << arg << std::endl; };

print(42);
print("hello world");

That lambda is mostly equivalent to

struct lambda {
    template <typename T>
    auto operator ()(const T& arg) const {
        std::cout << arg << std::endl;
    }
};

and then

lambda print;

print(42);
print("hello world");