Ask Your Question
2

Can the lambda expression be evaluated as constexpr in C++17?

asked 2023-06-16 22:21:31 +0000

pufferfish gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-16 22:27:02 +0000

qstack gravatar image

Yes, in C++17, lambda expressions can be evaluated as constexpr under certain conditions. According to the C++17 standard, a lambda expression can be constexpr if:

  1. The lambda body contains only the allowed statements and expressions that are allowed in a constexpr function.
  2. The lambda captures do not include this, correferenced variables, or variables with non-literal types.
  3. The lambda has no mutable or volatile qualifier.

If these conditions are met, the lambda can be declared as constexpr and evaluated at compile time.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-16 22:21:31 +0000

Seen: 11 times

Last updated: Jun 16 '23