<legend id='cn2y8'><style id='cn2y8'><dir id='cn2y8'><q id='cn2y8'></q></dir></style></legend>

      1. <small id='cn2y8'></small><noframes id='cn2y8'>

        • <bdo id='cn2y8'></bdo><ul id='cn2y8'></ul>
      2. <tfoot id='cn2y8'></tfoot>
        <i id='cn2y8'><tr id='cn2y8'><dt id='cn2y8'><q id='cn2y8'><span id='cn2y8'><b id='cn2y8'><form id='cn2y8'><ins id='cn2y8'></ins><ul id='cn2y8'></ul><sub id='cn2y8'></sub></form><legend id='cn2y8'></legend><bdo id='cn2y8'><pre id='cn2y8'><center id='cn2y8'></center></pre></bdo></b><th id='cn2y8'></th></span></q></dt></tr></i><div id='cn2y8'><tfoot id='cn2y8'></tfoot><dl id='cn2y8'><fieldset id='cn2y8'></fieldset></dl></div>

      3. 时间:2019-05-06 标签:c++find_iflambda

        时间:2023-07-01
        • <bdo id='qbU1i'></bdo><ul id='qbU1i'></ul>

          <small id='qbU1i'></small><noframes id='qbU1i'>

                  <i id='qbU1i'><tr id='qbU1i'><dt id='qbU1i'><q id='qbU1i'><span id='qbU1i'><b id='qbU1i'><form id='qbU1i'><ins id='qbU1i'></ins><ul id='qbU1i'></ul><sub id='qbU1i'></sub></form><legend id='qbU1i'></legend><bdo id='qbU1i'><pre id='qbU1i'><center id='qbU1i'></center></pre></bdo></b><th id='qbU1i'></th></span></q></dt></tr></i><div id='qbU1i'><tfoot id='qbU1i'></tfoot><dl id='qbU1i'><fieldset id='qbU1i'></fieldset></dl></div>
                    <tbody id='qbU1i'></tbody>
                  <tfoot id='qbU1i'></tfoot>

                  <legend id='qbU1i'><style id='qbU1i'><dir id='qbU1i'><q id='qbU1i'></q></dir></style></legend>
                1. 本文介绍了时间:2019-05-06 标签:c++find_iflambda的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  下面的代码有什么问题?如果结构体的第一个成员等于 0,它应该在结构体列表中找到一个元素.编译器抱怨 lambda 参数不是谓词类型.

                  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 the lambda argument not being of type predicate.

                  #include <iostream>
                  #include <stdint.h>
                  #include <fstream>
                  #include <list>
                  #include <algorithm>
                  
                  struct S
                  {
                      int S1;
                      int S2;
                  };
                  
                  using namespace std;
                  
                  int main()
                  {
                      list<S> l;
                      S s1;
                      s1.S1 = 0;
                      s1.S2 = 0;
                      S s2;
                      s2.S1 = 1;
                      s2.S2 = 1;
                      l.push_back(s2);
                      l.push_back(s1);
                  
                      list<S>::iterator it = find_if(l.begin(), l.end(), [] (S s) { return s.S1 == 0; } );
                  }
                  

                  推荐答案

                  代码在 VS2012 上工作正常,只是一个建议,按引用传递对象而不是按值传递:

                  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; } );
                  

                  这篇关于时间:2019-05-06 标签:c++find_iflambda的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:c++11/1y lambda 函数的类型签名是什么? 下一篇:将不可复制的闭包对象传递给 std::function 参数

                  相关文章

                  <tfoot id='7SIcr'></tfoot>

                    <legend id='7SIcr'><style id='7SIcr'><dir id='7SIcr'><q id='7SIcr'></q></dir></style></legend>
                      <bdo id='7SIcr'></bdo><ul id='7SIcr'></ul>

                    <i id='7SIcr'><tr id='7SIcr'><dt id='7SIcr'><q id='7SIcr'><span id='7SIcr'><b id='7SIcr'><form id='7SIcr'><ins id='7SIcr'></ins><ul id='7SIcr'></ul><sub id='7SIcr'></sub></form><legend id='7SIcr'></legend><bdo id='7SIcr'><pre id='7SIcr'><center id='7SIcr'></center></pre></bdo></b><th id='7SIcr'></th></span></q></dt></tr></i><div id='7SIcr'><tfoot id='7SIcr'></tfoot><dl id='7SIcr'><fieldset id='7SIcr'></fieldset></dl></div>

                    <small id='7SIcr'></small><noframes id='7SIcr'>