Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What type of variable that contain lambda [duplicate]

Tags:

c++

c++11

lambda

Can you explain which type of L in this context. In other words what type I can use instead auto keyword?

int main(){
 int x=0;
 auto L = [x] (int y)->bool{
   return x>y;
 };
  return 0; 
}
like image 739
Stepan Loginov Avatar asked Feb 13 '15 11:02

Stepan Loginov


People also ask

What is the type of lambda expression C++?

The type of a lambda expression is unspecified. But they are generally mere syntactic sugar for functors. A lambda is translated directly into a functor.

What is the use of lambda function in C++?

C++ Lambda expression allows us to define anonymous function objects (functors) which can either be used inline or passed as an argument. Lambda expression was introduced in C++11 for creating anonymous functors in a more convenient and concise way.

What is lambda expression in C++ Mcq?

Explanation: Lambda expression is a technique available in C++ that helps the programmer to write inline functions that will be used once in a program and so there is no need of providing names top them. Hence they are a type of inline functions without names.

Does C have lambda?

the C standard does not define lambdas at all but the implementations can add extensions. Gcc also added an extension in order for the programming languages that support lambdas with static scope to be able to convert them easily toward C and compile closures directly.


1 Answers

There is nothing in C++11 which you could use instead of auto in this context that would mean the exact same type. That's because the type of each lambda expression is a unique, unnamed type. Quoting C++11 5.1.2/3:

The type of the lambda-expression (which is also the type of the closure object) is a unique, unnamed non-union class type — called the closure type — whose properties are described below. ...

like image 169
Angew is no longer proud of SO Avatar answered Oct 07 '22 03:10

Angew is no longer proud of SO