Is it good approach to “pass” function template as generic-variadic lambda return statement?

半城伤御伤魂 提交于 2019-12-04 14:29:49

I recommend using perfect forwarding, but aside from that it's a perfectly viable (and probably the only aside from manually typing it all) approach to the problem.

So, that would be:

#define PASS_TEMPLATE(name) [](auto&&... args){return name(decltype(args)(args)...);}

GCC was broken with generic stateless lambdas, so you had to add at least minimal state like [dummy=nullptr] or something like that. Luckily they fixed it.

It is fine, except you would probably want to enable perfect forwarding:

#define PASS_TEMPLATE(name) [](auto&&... args){return name(std::forward<decltype(args)>(args)...);}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!