#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 = [a](){ 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+CnN0cnVjdCBpc19zdGF0ZWxlc3MKewogICAgc3RhdGljIGNvbnN0IGJvb2wgdmFsdWUgPSBoZWxwZXI8VCxUPjo6dmFsdWU7Cn07CiAgICAgICAgCmludCBtYWluKCkgCnsKICAgIGludCBhOwogICAgYXV0byBsMSA9IFthXSgpeyByZXR1cm4gMTsgfTsKICAgIGF1dG8gbDIgPSBbXSgpeyByZXR1cm4gMjsgfTsKICAgIGF1dG8gbDMgPSBbJmFdKCl7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