2

I need an explanation for this. How does lambda differ from others function to it don't be allowed? Is this a nonsense to be not part of C++ standard? for example, I wanted to write a "nested" function in C++ but like it isn't possible to do directly I do use lambda instead of. This function does a very small job: take a single int parameter and multiply with some values and returns. This values are locals to where lambda function is defined and all them are constexpr and know at run-time for this reason I do want to let the compiler put a const value instead of call the function. It's very often used function (that's why I write this as function) and I don't want this beging computed at run-time.

4
  • 1
    Please provide your code. Commented Mar 29, 2014 at 20:55
  • 1
    n2859 says "N2859 notes that severe implementation difficulties would arise if lambdas were permitted in contexts which require their contents to be part of a mangled name, and the prohibition on lambdas in constant expressions form part of the resolution to those difficulties." But this seems like a self-reference, and the linked PDF doesn't contain anything about constexpr or constant expressions as far as I can see. Commented Mar 29, 2014 at 20:59
  • @iavr: I don't understand how it will be useful Commented Mar 29, 2014 at 21:05
  • Oops, I got tricked by the address bar of my browser.. The quote is from N3597. Commented Mar 29, 2014 at 21:14

1 Answer 1

4

It is because the standard list lambda as non constant expression : "5.19 Constant expressions" … "is a core constant expression unless it involves one of the following as a potentially evaluated subexpression" … "— a lambda-expression (5.1.2);"

That is enough for any compiler to reject constexpr function with a lambda involved.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.