c++ find_if lambda

前端 未结 1 681
忘掉有多难
忘掉有多难 2020-12-05 16:57

What is wrong with the code below? It is supposed to find an element in the list of structs if the first of the struct\'s members equals to 0. The compiler complains about

相关标签:
1条回答
  • 2020-12-05 17:54

    Code works fine on VS2012, just one recommendation, pass object by reference instead of pass by value:

    list<S>::iterator it = find_if(l.begin(), l.end(), [] (const S& s) { return s.S1 == 0; } );
    
    0 讨论(0)
提交回复
热议问题