如何使用set::key_comp 和 set::value_comp 标准模板库 (STL) 函数
来源:互联网 发布:2016年网络第一红歌 编辑:程序博客网 时间:2024/04/29 23:56
下面的代码示例演示如何使用 Visual C++ set::key_comp 和 set::value_comp 的 STL 功能。
所需要的头文件:<set>
原型
template<class _K, class _Pr, class _A> class set { public: // Function 1: key_compare key_comp() const; // Function 2: value_compare value_comp() const; }注意在原型中的类/参数名称可能与中的头文件的版本不匹配。一些已被修改以提高可读性。
说明
Key_comp 函数返回存储的函数对象,用于确定受控序列中元素的顺序。Value_comp 函数将返回相同的功能的函数对象。示例代码:
////////////////////////////////////////////////////////////////////// // // Compile options needed: -GX// // SetComp.cpp:// Illustrates how to use the key_comp function to obtain a// function pointer that is the stored function object that// determines the order of elements in the controlled sequence.// It also illustrates how to use the value_comp function to// obtain a function pointer that is the stored function object// that determines the order of the elements in the controlled// sequence (same as key_comp result).// // Functions:// // key_comp Returns a function pointer to the function that// determines the order of elements in the controlled// sequence.// value_comp Returns a function pointer to the function that// determines the order of elements in the controlled// sequence (same as key_comp).// // Written by Derek Jamison// of Microsoft Technical Support,// Copyright (c) 1996 Microsoft Corporation. All rights reserved.////////////////////////////////////////////////////////////////////// #pragma warning(disable:4786)#include <set>#include <iostream>#if _MSC_VER > 1020 // if VC++ version is > 4.2 using namespace std; // std c++ libs implemented in std #endiftypedef set<int,less<int>,allocator<int> > SET_INT;void truefalse(int x){ cout << (x?"True":"False") << endl;}void main() { SET_INT s1; cout << "s1.key_comp()(8,10) returned "; truefalse(s1.key_comp()(8,10)); // True cout << "s1.value_comp()(8,10) returned "; truefalse(s1.value_comp()(8,10)); // True cout << "s1.key_comp()(10,8) returned "; truefalse(s1.key_comp()(10,8)); // False cout << "s1.value_comp()(10,8) returned "; truefalse(s1.value_comp()(10,8)); // False cout << "s1.key_comp()(8,8) returned "; truefalse(s1.key_comp()(8,8)); // False cout << "s1.value_comp()(8,8) returned "; truefalse(s1.value_comp()(8,8)); // False}
s1.key_comp()(8,10) returned True
s1.value_comp()(8,10) returned True
s1.key_comp()(10,8) returned False
s1.value_comp()(10,8) returned False
s1.key_comp()(8,8) returned False
s1.value_comp()(8,8) returned False
- 如何使用set::key_comp 和 set::value_comp 标准模板库 (STL) 函数
- set::key_comp
- STL 标准模板库之<set>详解
- 标准库STL中的map和set
- 标准模板库(STL)学习探究之Set容器
- 标准模板库(STL)学习探究之Set容器
- 标准模板库(STL)学习指南之set集合
- 标准模板库 STL—— set 列传
- STL标准模版库---set操作
- C++ 标准模板库STL set 使用方法与应用介绍(二)
- C++ 标准模板库STL set 使用方法与应用介绍(一)
- C++ 标准模板库STL set 使用方法与应用介绍(三)
- STL库:set和map的使用和原理
- STL库的map和set的使用
- STL set和multiset的使用
- c++ STL set和multiset的使用
- C++ STL set和multiset的使用
- C++ STL set和multiset的使用
- 简化的ajax +时间倒计时控件
- 用户级线程和内核级线程
- Red5 流处理架构设计解析
- 多CPU的私有数据存储
- 婚外情网站Ashley Madison登陆香港
- 如何使用set::key_comp 和 set::value_comp 标准模板库 (STL) 函数
- HP-UX自启动和关闭
- Linux 常用命令
- hdu 2871 Memory Control 伸展树区间合并
- uva 11248 - Frequency Hopping 最大流最小割入门题 求割集模板
- Deep Learning and Shallow Learning
- 黑马程序员——7K面试题之银行业务调度系统
- [[UIApplication sharedApplication] openURL:]加载其它应用
- 一种全新的VDI桌面虚拟化方案(X9BYOD)