<bdo id='uiGrr'></bdo><ul id='uiGrr'></ul>
        <tfoot id='uiGrr'></tfoot>

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

      1. <legend id='uiGrr'><style id='uiGrr'><dir id='uiGrr'><q id='uiGrr'></q></dir></style></legend>

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

      3. std::vector 删除满足某些条件的元素

        时间:2023-09-15

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

          1. <legend id='5VLUB'><style id='5VLUB'><dir id='5VLUB'><q id='5VLUB'></q></dir></style></legend>
            <tfoot id='5VLUB'></tfoot>
                <tbody id='5VLUB'></tbody>

              1. <small id='5VLUB'></small><noframes id='5VLUB'>

                  <bdo id='5VLUB'></bdo><ul id='5VLUB'></ul>
                  本文介绍了std::vector 删除满足某些条件的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  正如标题所说,我想删除/合并满足特定条件的向量中的对象.我的意思是我知道如何从向量中删除整数,例如,其值为 99.

                  As the title says I want to remove/merge objects in a vector which fulfill specific conditions. I mean I know how to remove integers from a vector which have the value 99 for instance.

                  Scott Meyers 的 remove 成语:

                  The remove idiom by Scott Meyers:

                  vector<int> v;
                  v.erase(remove(v.begin(), v.end(), 99), v.end());
                  

                  但是假设是否有一个包含延迟成员变量的对象向量.现在我想消除所有延迟差异仅小于特定阈值的对象,并希望将它们组合/合并为一个对象.

                  But suppose if have a vector of objects which contains a delay member variable. And now I want to eliminate all objects which delays differs only less than a specific threshold and want to combine/merge them to one object.

                  过程的结果应该是一个对象向量,其中所有延迟的差异至少应该是指定的阈值.

                  The result of the process should be a vector of objects where the difference of all delays should be at least the specified threshold.

                  推荐答案

                  std::remove_if来拯救!

                  99 将被替换为 UnaryPredicate,它会过滤您的延迟,我将使用 lambda 函数来实现.

                  99 would be replaced by UnaryPredicate that would filter your delays, which I am going to use a lambda function for.

                  这是一个例子:

                  v.erase(std::remove_if(
                      v.begin(), v.end(),
                      [](const int& x) { 
                          return x > 10; // put your condition here
                      }), v.end());
                  

                  这篇关于std::vector 删除满足某些条件的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

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

                  <small id='9EYUt'></small><noframes id='9EYUt'>

                      <tfoot id='9EYUt'></tfoot>
                      • <bdo id='9EYUt'></bdo><ul id='9EYUt'></ul>
                          <legend id='9EYUt'><style id='9EYUt'><dir id='9EYUt'><q id='9EYUt'></q></dir></style></legend>