简体   繁体   中英

C++14 combining generic lambdas and variable templates

I know about generic lambdas , and I know about variable templates, but, what does this do? Is it even allowed?

template<typename T>
auto f = [](auto a, T b){ /**/ };

If it's allowed, can it be used as expected? That is, as f<type>(var_a, var_b) ?

A variable template must be declared constexpr . A lambda cannot occur in a constant-expression , so the initialisation is not allowed, and its operator() is not declared constexpr , so calling it isn't allowed.

In summary, this is ill-formed in the current C++14 draft.

Note: curiously, even though a lambda-expression cannot occur in a constant-expression , it seems that the closure type of a lambda may have a constexpr copy/move constructor.

该代码现在在C ++ 14的当前草案中是合法的,并且可以使用clang 3.5 trunk进行编译

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM