Lambdas in an Unevaluated Context and Stateless Lambdas

Admittedly, the title of this lesson contains two terms that may be new to you: unevaluated context and stateless lambda. Let me start with unevaluated context.

Unevaluated context

The following code snippet has a function declaration and a function definition.

int add1(int, int); // declaration
int add2(int a, int b) { return a + b; } // definition

Function add1 is declared, while add2 is defined. This means, if you use add1 in an evaluated context, for example, by invoking it, you get a link-time error. The key observation is that you can use add1 in unevaluated contexts, such as typeid or decltype. Both operators accept unevaluated operands.

Run the program below.

Get hands-on with 1400+ tech skills courses.