mardi 20 février 2018

Lambda expression arguments, C++11

This example is from Stroustrup 4th edition in Lambda expressions section. Although this book is a perfect tutorial for learning C++11, the author here confused me with this example and can't understand explanation. What does [&os,m] mean??

void print_modulo(const vector<int>& v, ostream& os, int m)
// output v[i] to os if v[i]%m==0
{
    for_each(begin(v),end(v), [&os,m](int x) { if (x%m==0) os << x << '\n'; });
}

Aucun commentaire:

Enregistrer un commentaire