Test if a lambda is stateless?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How would I go about testing if a lambda is stateless, that is, if it captures anything or not? My guess would be using overload resolution with a function pointer overload, or template specialization? int a; auto l1 = [a](){ return 1; }; auto l2 = [](){ return 2; }; // test l1 and l2, get a bool for statelessness. 回答1: As per the Standard, if a lambda doesn't capture any variable, then it is implicitly convertible to function pointer. Based on that, I came up with is_stateless<> meta-function which tells you whether a lambda is stateless or