//////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// remove.cpp : This example shows how to use list::remove and
// list::remove_if. It also shows how to use
// list::remove_if with your own function.
//
// Functions:
//
// list::remove
// list::remove_if
//
// Written by Andrew Bradnan
// Copyright (c) 1996 Microsoft Corporation. All rights reserved.
//////////////////////////////////////////////////////////////////////
#pragma warning(disable:4786) // disable spurious C4786 warnings
#include <list>
#include <string>
#include <iostream>
using namespace std;
#if _MSC_VER > 1020 // if later than revision 4.2
using namespace std; // std c++ libs are implemented in std
#endif
typedef list<string, allocator<string> > LISTSTR;
// Used to customize list::remove_if()
class is_four_chars
: public not_equal_to<string>
{
bool operator()(const string& rhs, const string&) const
{ return rhs.size() == 4; }
};
void main()
{
LISTSTR test;
LISTSTR::iterator i;
test.push_back("good");
test.push_back("bad");
test.push_back("ugly");
// good bad ugly
for (i = test.begin(); i != test.end(); ++i)
cout << *i << " ";
cout << endl;
test.remove("bad");
// good ugly
for (i = test.begin(); i != test.end(); ++i)
cout << *i << " ";
cout << endl;
// remove any not equal to "good"
test.remove_if(binder2nd<not_equal_to<string> >
(not_equal_to<string>(), "good"));
// good
for (i = test.begin(); i != test.end(); ++i)
cout << *i << " ";
cout << endl;
// Remove any strings that are four characters long
test.remove_if(binder2nd<not_equal_to<string> >
(is_four_chars(), "useless parameter"));
if (test.empty())
cout << "Empty list\n";
}
http://support.microsoft.com/kb/168047/zh-tw
分享到:
相关推荐
1.5.1 string与remove 13 1.5.2 string与unique、sort 13 1.5.3 string与search 13 1.5.4 string和find、find_if 14 1.5.5 string与copy、copy_if 14 1.5.6 string与count、count_if 15 1.6 string与wstring 15 ...
34.37 remove,remove_if,remove copy和remove_copy_if 34.38 replace,replace_copy,replace_if和replace_copy_if 34.39 reverse和reverse_copy 34.40 rotate和rotate_copy 34.41 search 34.42 search_n 34.43 ...
5. remove / remove_if 30 6. unique 31 7. rotate 32 8. random_shuffle 32 9. partition / stable_partition 33 10. sort / stable_sort 33 11. partial_sort 34 12. nth_element 34 13. lower_bound / upper_...
除去表中的重复项,本例程未用到此函数 (defun remove:same (lst / re) (foreach n lst (if (member n re) () (setq re (append re (list re))) ) ) re ) ;;获得实体的长度 (defun get:len (e) (vlax-curve-...
22.18 条件移除remove_if 321 22.19 不连续重复元素复制unique_copy 322 22.20 剔除连续重复元素unique 324 22.21 元素反向reverse 325 22.22 反向复制reverse_copy 326 22.23 旋转rotate 327 22.24 ...
22.18 条件移除remove_if 321 22.19 不连续重复元素复制unique_copy 322 22.20 剔除连续重复元素unique 324 22.21 元素反向reverse 325 22.22 反向复制reverse_copy 326 22.23 旋转rotate 327 22.24 ...
22.18 条件移除remove_if 321 22.19 不连续重复元素复制unique_copy 322 22.20 剔除连续重复元素unique 324 22.21 元素反向reverse 325 22.22 反向复制reverse_copy 326 22.23 旋转rotate 327 22.24 ...
条款36: 用not1和remove_copy_if来表现copy_if 条款37: 用accumulate或for_each来统计序列 仿函数,仿函数类,函数等等 条款38: 把仿函数类设计成值传递的 条款39: 用纯函数做predicate 条款40: 增强仿函数类的...
这篇文章的目的是为了介绍...本文中还讨论了条件函数和函数指针在迭代算法中使用,如在remove_if()和for_each()中的使用。通过阅读这篇文章读者应该能够有效地使用vector容器,而且应该不会再去使用C类型的动态数组了。
/*将device_driver中的probe,remove,shutdown函数指针指向platform_driver中的函数,后面进行驱动和设备绑定后会调用probe函数 */ if (drv->probe) drv->driver.probe = platform_drv_probe; if (drv->...
条款36: 用not1和remove_copy_if来表现copy_if 条款37: 用accumulate或for_each来统计序列 仿函数,仿函数类,函数等等 条款38: 把仿函数类设计成值传递的 条款39: 用纯函数做predicate 条款40: 增强仿函数类的...
20.5.3 remove、remove_if、 remove_copy和remove_copy_if 20.5.4 replace、replace_if、replace_copy和replace_copy_if 20.5.5 数学算法 20.5.6 基本查找与排序算法 20.5.7 swap、iter_swap和swap_ranges...
20.5.3 remove、remove_if、 remove_copy和remove_copy_if 20.5.4 replace、replace_if、replace_copy和replace_copy_if 20.5.5 数学算法 20.5.6 基本查找与排序算法 20.5.7 swap、iter_swap和swap_ranges...
remove_if 357 remove_copy_if 358 replace 359 replace_copy 359 replace_if 359 replace_copy_if 360 reverse 360 reverse_copy 361 rotate 361 rotate_copy 365 search 365 search_n 366 swap_ranges...
删除数组中为空值的元素就可以使用这个函数。 复制代码 代码如下://删除数组中的一个元素 function array_remove_value(&$arr, $var){ foreach ($arr as $key => $value) { if (is_array($value)) { array_remove_...
remove_if 357 remove_copy_if 358 replace 359 replace_copy 359 replace_if 359 replace_copy_if 360 reverse 360 reverse_copy 361 rotate 361 rotate_copy 365 search 365 search_n 366 swap_ranges...
目录 python的高阶函数 1、假如你想从一个考试分数的列表中删除所有的0分,怎么办? 普通程序员: 高级程序员: 2、filter函数 3、给定一个数列[1,3,5,6,7,9,10,435],求数列中每一项相乘的结果 ... if numbe
本文中还讨论了条件函数和函数指针在迭代算法中使用,如在remove_if()和for_each()中的使用。通过阅读这篇文章读者应该能够有效地使用vector容器,而且应该不会再去使用C类型的动态数组了。 Vector总览 vector是...
1.5.1 string与remove 12 1.5.2 string与unique、sort 12 1.5.3 string与search 12 1.5.4 string和find、find_if 13 1.5.5 string与copy、copy_if 13 1.5.6 string与count、count_if 14 1.6 string与wstring 14 ...
if item == '0': dat.remove(item) print(dat) #按要求是把'0'都删掉的,输出结果是['1', '2', '3', '0'] ?? 首先,remove(x) 移除的是序列首次碰到的元素x 理解: 遍历列表,item每一次都会变化,可以想象有一...