#include <iostream>
#include <type_traits>
template <typename T, typename U>
struct helper : helper<T, decltype(&U::operator())>
{};
template <typename T, typename C, typename R, typename... A>
struct helper<T, R(C::*)(A...) const>
{
static const bool value = std::is_convertible<T, R(*)(A...)>::value;
};
template<typename T>
struct is_stateless
{
static const bool value = helper<T,T>::value;
};
int main()
{
int a;
auto l1 = [](){ return 1; };
auto l2 = [](){ return 2; };
auto l3 = [&a](){ return 2; };
std::cout << std::boolalpha << is_stateless<decltype(l1)>::value << "\n";
std::cout << std::boolalpha << is_stateless<decltype(l2)>::value << "\n";
std::cout << std::boolalpha << is_stateless<decltype(l3)>::value << "\n";
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dHlwZV90cmFpdHM+Cgp0ZW1wbGF0ZSA8dHlwZW5hbWUgVCwgdHlwZW5hbWUgVT4Kc3RydWN0IGhlbHBlciA6IGhlbHBlcjxULCBkZWNsdHlwZSgmVTo6b3BlcmF0b3IoKSk+Cnt9OwogICAgICAgIAp0ZW1wbGF0ZSA8dHlwZW5hbWUgVCwgdHlwZW5hbWUgQywgdHlwZW5hbWUgUiwgdHlwZW5hbWUuLi4gQT4Kc3RydWN0IGhlbHBlcjxULCBSKEM6OiopKEEuLi4pIGNvbnN0PiAKewogICAgc3RhdGljIGNvbnN0IGJvb2wgdmFsdWUgPSBzdGQ6OmlzX2NvbnZlcnRpYmxlPFQsIFIoKikoQS4uLik+Ojp2YWx1ZTsKfTsKCnRlbXBsYXRlPHR5cGVuYW1lIFQ+CnN0cnVjdCBpc19zdGF0ZWxlc3MKewogICAgc3RhdGljIGNvbnN0IGJvb2wgdmFsdWUgPSBoZWxwZXI8VCxUPjo6dmFsdWU7Cn07CiAgICAgICAgCmludCBtYWluKCkgCnsKICAgIGludCBhOwogICAgYXV0byBsMSA9IFtdKCl7IHJldHVybiAxOyB9OwogICAgYXV0byBsMiA9IFtdKCl7IHJldHVybiAyOyB9OwogICAgYXV0byBsMyA9IFsmYV0oKXsgcmV0dX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