STL 源码分析 # stl_pair #
来源:互联网 发布:网络交友新时空图片 编辑:程序博客网 时间:2024/05/16 08:28
STL 源码分析 # stl_pair #
pair是一种很简单也很常用的关联容器(associative container).
/***********************************************Programmer:EOFDate:2015.04.10File:pair.cppE-mail:jasonleaster@gmail.com***********************************************/#include <iostream>#include <string>using namespace std;int main(int argc, char const *argv[]){pair<int, int> int_pair(100, 200);pair<string, int> si_pair("hello world", 42);pair<string, string> ss_pair("jason", "leaster");cout << int_pair.first << " " << int_pair.second << endl;cout << si_pair.first << " " << si_pair.second << endl;cout << ss_pair.first << " " << ss_pair.second << endl;return 0;}
很难得啊...pair数据类型的数据成员居然不是私有成员~
我们看看pair的实现:
这是我到目前为止在STL里面看到的最简单的数据抽象... ...
支持的各种比较运算符:
template <class _T1, class _T2>inline bool operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y){ return __x.first == __y.first && __x.second == __y.second; }template <class _T1, class _T2>inline bool operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y){ return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second); }#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDERtemplate <class _T1, class _T2>inline bool operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) { return !(__x == __y);}template <class _T1, class _T2>inline bool operator>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) { return __y < __x;}template <class _T1, class _T2>inline bool operator<=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) { return !(__y < __x);}template <class _T1, class _T2>inline bool operator>=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) { return !(__x < __y);}
而make_pair函数其实本质上也就是调用了构造函数....
0 0
- STL 源码分析 # stl_pair #
- 《STL源码剖析》-- stl_pair.h
- 《STL源码剖析》---stl_pair.h阅读笔记
- STL源码剖析——stl_pair.h学习
- STL源码剖析 [容器](四)[stl_pair.h]
- STL_pair
- stl源码分析请教
- [STL]源码分析:allocator
- STL hashtable 源码分析
- STL源码分析--list
- STL源码分析--deque
- STL源码分析--算法
- STL源码分析 # vector #
- STL 源码分析 # stl_number #
- C++ STL 源码分析
- STL源码分析(总结)
- STL源码分析set
- STL源码分析
- 1、学习面向对象 基本概念
- 学习GitHub
- python中的sum函数.sum(axis=1)
- Shell中for in 基础语法
- 关于Web大型系统的技术选型
- STL 源码分析 # stl_pair #
- PF_NETLINK应用实例NETLINK_KOBJECT_UEVENT具体实现--udev实现原理
- 2、面向对象——接口
- poj 1590Palindromes 简单模拟
- Android中Makefile编写
- stringstream clear()的误区
- 学习MVC随笔
- 3、学习面向对象——工厂设计模式
- iOS中UITextField 使用全面解析