<tfoot id='OmmEE'></tfoot><legend id='OmmEE'><style id='OmmEE'><dir id='OmmEE'><q id='OmmEE'></q></dir></style></legend>

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

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

        <bdo id='OmmEE'></bdo><ul id='OmmEE'></ul>

    1. std::remove_if - lambda,不从集合中删除任何内容

      std::remove_if - lambda, not removing anything from the collection(std::remove_if - lambda,不从集合中删除任何内容)
    2. <legend id='f3zX4'><style id='f3zX4'><dir id='f3zX4'><q id='f3zX4'></q></dir></style></legend>

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

          1. <tfoot id='f3zX4'></tfoot>

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

              • 本文介绍了std::remove_if - lambda,不从集合中删除任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                好吧,我想我在这里犯了一个愚蠢的错误.我有一个 DisplayDevice3d 列表,每个 DisplayDevice3d 都包含一个 DisplayMode3d 列表.我想从 DisplayDevice3d 列表中删除所有没有任何 DisplayMode3d 的项目.我正在尝试使用 Lambda 来做到这一点,即:

                Ok, I expect I've made a dumb mistake here. I have a list of DisplayDevice3d and each DisplayDevice3d contains a list of DisplayMode3d. I want to remove all items from the list of DisplayDevice3d that don't have any DisplayMode3d's. I'm trying to use a Lambda to do it, ie.:

                    // If the device doesn't have any modes, remove it.
                
                  std::remove_if(MyDisplayDevices.begin(), MyDisplayDevices.end(),
                   [](DisplayDevice3d& device) 
                   { 
                    return device.Modes.size() == 0; 
                   }
                  ); 
                

                即使在 MyDisplayDevices 中的 6 个 DisplayMode3d 中,只有 1 个在其 Modes 集合中有任何 DisplayMode3d,但没有从列表中删除任何内容.

                Even though out of 6 DisplayMode3d's in MyDisplayDevices, only 1 has any DisplayMode3d's in its Modes collection, nothing is being removed from the list.

                我在这里犯了什么大错?

                What numpty mistake have I made here?

                好吧,我的错误是我应该使用 MyDisplayDevices.remove_if 而不是 std::remove_if,但是下面的答案对于使用 std::remove_if :p 是正确的.

                Ah ok, my mistake was I should be using MyDisplayDevices.remove_if instead of std::remove_if, however the answers below are correct for use of std::remove_if :p.

                MyDisplayDevices.remove_if( [](DisplayDevice3d const & device) 
                                            { 
                                                return device.Modes.size() == 0; 
                                            });
                

                推荐答案

                你需要对 remove_if 返回的迭代器调用erase,它应该是这样的:

                You need to call erase on the iterator returned from remove_if, It should look something like this:

                auto new_end = std::remove_if(MyDisplayDevices.begin(), MyDisplayDevices.end(),
                                              [](const DisplayDevice3d& device)
                                              { return device.Modes.size() == 0; });
                
                MyDisplayDevices.erase(new_end, MyDisplayDevices.end());
                

                这篇关于std::remove_if - lambda,不从集合中删除任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How to print vector#39;s data(如何打印矢量的数据)
                Visual C++ appends 0xCC (int3) bytes at the end of functions(Visual C++ 在函数末尾附加 0xCC (int3) 字节)
                How to use a variable inside a _T wrapper?(如何在 _T 包装器中使用变量?)
                MSVC++ warning flags(MSVC++ 警告标志)
                How to read file which contains uxxxx in vc++(如何在vc++中读取包含uxxxx的文件)
                stack overflow error in C++ program(C++程序中的堆栈溢出错误)
              • <legend id='wt769'><style id='wt769'><dir id='wt769'><q id='wt769'></q></dir></style></legend>
                  <tbody id='wt769'></tbody>
                <tfoot id='wt769'></tfoot>
                  <bdo id='wt769'></bdo><ul id='wt769'></ul>
                    <i id='wt769'><tr id='wt769'><dt id='wt769'><q id='wt769'><span id='wt769'><b id='wt769'><form id='wt769'><ins id='wt769'></ins><ul id='wt769'></ul><sub id='wt769'></sub></form><legend id='wt769'></legend><bdo id='wt769'><pre id='wt769'><center id='wt769'></center></pre></bdo></b><th id='wt769'></th></span></q></dt></tr></i><div id='wt769'><tfoot id='wt769'></tfoot><dl id='wt769'><fieldset id='wt769'></fieldset></dl></div>

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