stl_pair.h
- stl_pair.h
- // Filename: stl_pair.h
- // Comment By: 凝霜
- // E-mail: mdl2009@vip.qq.com
- // Blog: http://blog.csdn.net/mdl13412
- /*
- *
- * Copyright (c) 1994
- * Hewlett-Packard Company
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Hewlett-Packard Company makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- *
- * Copyright (c) 1996,1997
- * Silicon Graphics Computer Systems, Inc.
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Silicon Graphics makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- */
- /* NOTE: This is an internal header file, included by other STL headers.
- * You should not attempt to use it directly.
- */
- #ifndef __SGI_STL_INTERNAL_PAIR_H
- #define __SGI_STL_INTERNAL_PAIR_H
- __STL_BEGIN_NAMESPACE
- // pair只是一个wraper, 所以要提供最佳效率
- // 使用struct的原因是我们要能方便的存取内部元素
- // pair在关联式容器中的使用极为广泛, 其本身也可以嵌套使用
- template <class T1, class T2>
- struct pair
- {
- typedef T1 first_type;
- typedef T2 second_type;
- T1 first;
- T2 second;
- pair() : first(T1()), second(T2()) {}
- pair(const T1& a, const T2& b) : first(a), second(b) {}
- // 此版本并未提供operator =()的支持, 个人认为应该提供
- #ifdef __STL_MEMBER_TEMPLATES
- // 允许使用兼容的pair进行复制构造
- template <class U1, class U2>
- pair(const pair<U1, U2>& p) : first(p.first), second(p.second) {}
- #endif
- };
- // 只有当pair中的两个成员均相等时, 才判定两个pair相等
- // 使用自定义类型时最好提供operator ==重载
- 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;
- }
- // 连个pair进行比较操作时, 以第一个元素为主, 如果第一个元素不能决定表达式的值
- // 那么再进行第二个元素的比较
- // 使用自定义类型时最好提供operator <重载
- 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);
- }
- // 至于为什么没有提供operator !=, >, >=, <=
- // 这个是因为其在<stl_relops.h>中有实现, 其只依赖operator <和==
- // 所以在此特化operator ==, <就能满足要求
- // 提供<stl_relops.h>的作用是如果需要特化operator XXX
- // 那么我们仅需要特化operator ==和<即可同时重载所有operator
- // 这里使用了RVO(Return Value Optimization)机制, 如果编译器支持,
- // 则可以消除临时对象的构造和析构负担
- // 详细细节见<Inside The C++ Object Model>
- template <class T1, class T2>
- inline pair<T1, T2> make_pair(const T1& x, const T2& y)
- {
- return pair<T1, T2>(x, y);
- }
- __STL_END_NAMESPACE
- #endif /* __SGI_STL_INTERNAL_PAIR_H */
- // Local Variables:
- // mode:C++
- // End:
stl_pair.h的更多相关文章
- STL源代码剖析 容器 stl_map.h
本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie map ------------------------------------------ ...
- stl_algobase.h
stl_algobase.h // Filename: stl_algobase.h // Comment By: 凝霜 // E-mail: mdl2009@vip.qq.com // Blog: ...
- stl_stack.h
stl_stack.h // Filename: stl_stack.h // Comment By: 凝霜 // E-mail: mdl2009@vip.qq.com // Blog: http:/ ...
- stl_queue.h
stl_queue.h // Filename: stl_queue.h // Comment By: 凝霜 // E-mail: mdl2009@vip.qq.com // Blog: http:/ ...
- STL源代码剖析——基本算法stl_algobase.h
前言 在STL中.算法是常常被使用的,算法在整个STL中起到很关键的数据.本节介绍的是一些基本算法,包括equal.fill.fill_n,iter_swap.lexicographical_comp ...
- construction const parameter问题 构造函数const引用参数问题
工程在window下编译没有任何问题, 但是在linux(CentOS6)下编译就老是报错 C++ 编译器已升级到最新版 6.1.0 错误如下: In file included /bits/stl_ ...
- NDK(17)让ndk支持完整C++,exception,rtti,
C++ Support The Android platform provides a very minimal C++ runtime support library (/system/lib/li ...
- 【转载】【挖掘Treap的潜力】
原帖: http://fanhq666.blog.163.com/blog/static/819434262011021105212299/ 你的Treap能支持以下操作吗?1.区间增减 2.区间求最 ...
- thread - 传递引用参数
当给 thread 的执行函数传递指针参数时,没有任何问题,但是如果想传递引用,按照普通函数的调用方法会遇到编译失败: #include <iostream> #include <t ...
随机推荐
- LNMP环境搭建(三:PHP)
1.获取php源码 # cd /usr/local/src/ # wget http://cn2.php.net/get/php-7.0.15.tar.gz/from/this/mirror 2.解压 ...
- Web客户端语言HTML、XHTML和XML相关知识介绍
HTML简介 HTML(Hyper Text Mark-up Language)即超文本标记语言或超文本链接标示语言,是目前网络上应用最为广泛的语言,也是构成网页文档的主要语言.HTML文本是由HTM ...
- 爬虫入门【7】Python-文件的读写和JSON
文本文档的读写 最重要的open()方法将返回一个file对象,经常使用的两个参数为open(filename,mode) 其中,filename为file保存的地址,可以是本地地址,相对地址或者绝对 ...
- 前端开发中js变量定义及命名的规范建议
关于变量定义及命名 现在谈谈关于变量及方法等的命名,没有硬性规定,但为了规范,遵循一些约定还是很有必要的. 变量定义:好的做法是把将要使用的变量名用一个var关键字一并定义在代码开头,变量名间用逗号隔 ...
- HTML-Table-Td固定宽度使内容换行
table style="TABLE-LAYOUT: fixed;" td style="WORD-WRAP: break-word;WIDTH:200px;"
- ASP向上取整
<%Function Ceil(value) Dim return return = int(value) Cei2=value-return if Cei2>0 ...
- 我的Android进阶之旅------>关于android:layout_weight属性的一个面试题
最近碰到一个面试题,按照下图,由Button和EditText组成的界面下厨布局代码,解决这题目需要使用android:layout_weight的知识. 首先分析上图所示的界面可以看成一下3个部分. ...
- 模仿jquery框架源码 -生长---跨域访问
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...
- POJ - 3414 Pots 【BFS】
题目链接 http://poj.org/problem?id=3414 题意 给出两个杯子 容量分别为 A B 然后给出C 是目标容量 有三种操作 1 将一个杯子装满 2.将一个杯子全都倒掉 3.将一 ...
- 剑指offer——圆圈中最后剩下的数字
1.如果通过环形列表去模拟圆圈的话,最后时间复杂度为O(mn),而且还需要一个辅助链表来模拟圆圈,空间复杂度为O(n). 2.通过找出递推公式的方法,求得递推公式为 时间复杂度为O(n),空间复杂度为 ...