lundi 21 janvier 2019

how to know how many parameter sud be passed to lambda expression

I am really new to c++11, So while understanding the lamda expression i am full of doubt. I am not able to understand how many parameter should be passed to the lamda expression.

like

vector<int> v {4, 1, 3, 5, 2, 3, 1, 7};
vector<int>:: iterator p = find_if(v.begin(), v.end(), [](int i) 
    { 
        return i > 4; 
    });

here only 1 argument is passed to the lamda function. and what is the value i and from where its passed to lamda.

But in the below case 2 arguments are passed

sort(v.begin(), v.end(), [](const int& a, const int& b) -> bool
    { 
        return a > b; 
    });

from where these two value are passed to the lamda, Kindly explain it, please clear my doubts

Aucun commentaire:

Enregistrer un commentaire