[C++][](){} and []{}()

When I was studying, I suddenly saw the usage of two lambda expressions in the example. [](){}I []{}()suddenly felt confused
about this usage . After checking, the former is a standard lambda expression usage , while the latter is a shorthand version of lambda + call, that is, omitted () used for parameter passing, and calls itself directly after constructing the anonymous function . For example:[]{}()
[](){}
[]{}()

int c = [](int n){
    
    
	return [n](int x){
    
     
		return n + x;
	}(1);
};
a = c(2);

int c = [](int n){
    
    
	return [n]{
    
     
		return 1;
	}();
}(2);

Guess you like

Origin blog.csdn.net/qq_43557907/article/details/125667737
C++