Called a Lambda expression in C + +11 introduced a new concept .Used to explain the concept with some examples .Lambda expression in the concept of the origin of C + + 11( Also written as λ - calculus ) Lambda calculus , functional usekuraprēķina expression programming based onAbstraction functions , variable binding and substitution .Instead , clear the name of a function to be anonymousλ - calculus . C + +11 Lambda expression to define a non- anonymousFunction takes the following form :[ Capture ] ( parameters ) -> {return_type function_body}> { T } , where T - [ ] ( [ ] ) { } , or ( ), a simple form of variableReturn type of functionsSo a couple of brackets [ ] is a list of external variablesLambda functions, variables to be captured during the coveredValue or by reference . Options include as norādītsšādasTable :A pair of brackets , ie , ( ) , as is a list of argumentsFunction is given . A pair of braces { } is the body nesfunkcijaJalambda that gets executed is actually called . CompensationLambda functions can be selected to be ignored in such a lightImplicit type decltype (return_ with a return statementReport ) . We Lambda determining variable , can be labeledBy value, the values are not changed .For example , [ ] ( int x , int y ) {x + y return ; }Return indirectly , to the return typeExpression (decltype (x + y ) ) . Five Lambda type of return may beAll equations are released to return to the same type .Lambda būtslēgšanu is optional .An example of the program are as follows :Include # <iostream>Include # <string>Include # <vector>Include # <algorithm>Using namespace std ;Template <typename T>ostream and operator << (ostream & O,const vector <T> and V ){( Auto and Power V ) { forElectrically << s << " " ;}Return s ;}Int main ( ){Vector of <int> = {10, 12, 15, 20, 25, 27};cout << "( before ):" << endl << number ;Int x = 5 ;nos.erase (remove_if (nos.begin () nos.end ()[X] ( int number ) { return number % X = 0;! } )nos.end ());cout << "( Back ):" << endl << number ;Return 0 ;}(C + compiler, using 11 If so , ) Output :( A ) 10 12 15 20 25 27( A ) 10 15 20 25Let 's explain . provides an interesting example <algorithm>Removed from the list of feature elements that are renove_ifBased on specific criteria . It takes the form of sample<class ForwardIterator, class UnaryPredicate>ForwardIterator remove_if(ForwardIterator first , ForwardIterator lastUnaryPredicate pred);This function is called , the range [Fi RST 's ) turnPred returns right away with all the elements of the series ,And the end of the series gives an iterator .In our example , we have to stop using Lambda functionsFive things to remove the entire vector , the elements( In this case , 5 ) are divided . Thus , { 10 , 12 of the initial list ,15 , 20 , 25 , 27 } { numbers 10 , 15 , 20 , 25 } rupantari
No comments:
Post a Comment