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的更多相关文章

  1. STL源代码剖析 容器 stl_map.h

    本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie map ------------------------------------------ ...

  2. stl_algobase.h

    stl_algobase.h // Filename: stl_algobase.h // Comment By: 凝霜 // E-mail: mdl2009@vip.qq.com // Blog: ...

  3. stl_stack.h

    stl_stack.h // Filename: stl_stack.h // Comment By: 凝霜 // E-mail: mdl2009@vip.qq.com // Blog: http:/ ...

  4. stl_queue.h

    stl_queue.h // Filename: stl_queue.h // Comment By: 凝霜 // E-mail: mdl2009@vip.qq.com // Blog: http:/ ...

  5. STL源代码剖析——基本算法stl_algobase.h

    前言 在STL中.算法是常常被使用的,算法在整个STL中起到很关键的数据.本节介绍的是一些基本算法,包括equal.fill.fill_n,iter_swap.lexicographical_comp ...

  6. construction const parameter问题 构造函数const引用参数问题

    工程在window下编译没有任何问题, 但是在linux(CentOS6)下编译就老是报错 C++ 编译器已升级到最新版 6.1.0 错误如下: In file included /bits/stl_ ...

  7. NDK(17)让ndk支持完整C++,exception,rtti,

    C++ Support The Android platform provides a very minimal C++ runtime support library (/system/lib/li ...

  8. 【转载】【挖掘Treap的潜力】

    原帖: http://fanhq666.blog.163.com/blog/static/819434262011021105212299/ 你的Treap能支持以下操作吗?1.区间增减 2.区间求最 ...

  9. thread - 传递引用参数

    当给 thread 的执行函数传递指针参数时,没有任何问题,但是如果想传递引用,按照普通函数的调用方法会遇到编译失败: #include <iostream> #include <t ...

随机推荐

  1. Java是否存在内存泄露

    会的. 原因:长生命周期的对象持有短生命周期对象的引用,导致短生命周期对象不能被回收,由此可能发生内存泄露. 举例参考:http://blog.csdn.net/yakihappy/article/d ...

  2. 【BZOJ2422】Times 树状数组

    [BZOJ2422]Times Description 小y作为一名资深的dotaer,对视野的控制有着深刻的研究.每个单位在一段特定的时间内会出现在小y的视野内,除此之外的时间都在小y看不到的地方. ...

  3. 【BZOJ3143】[Hnoi2013]游走 期望DP+高斯消元

    [BZOJ3143][Hnoi2013]游走 Description 一个无向连通图,顶点从1编号到N,边从1编号到M. 小Z在该图上进行随机游走,初始时小Z在1号顶点,每一步小Z以相等的概率随机选 ...

  4. iOS 开发与H5交互(JavaScriptCore框架的使用)

    现在的iOS项目中嵌入了越来越多的Web界面,当然是为了方便,那么为了迎合这一趋势,作为iOS开发程序员,我们必须要了解怎么样用OC去和这些Web界面进行交互.这里介绍的是JavaScriptCore ...

  5. python中TCP和UDP区别

    TCP(Transmission Control Protocol)可靠的.面向连接的协议(eg:打电话).传输效率低全双工通信(发送缓存&接收缓存).面向字节流.使用TCP的应用:Web浏览 ...

  6. Android N API预览

    Android N for Developers 重要的开发人员功能 多窗体支持 通知 JIT/AOT 编译 高速的应用安装路径 外出瞌睡模式 后台优化 Data Saver 高速设置图块 API 号 ...

  7. Unity3D C#事件管理:EventManager

    原文地址:http://bbs.9ria.com/thread-153258-1-1.html 原project地址:https://github.com/djandrew/UnityEventMan ...

  8. linux c编程:Posix共享内存区

    Posix共享内存区:共享内存是最快的可用IPC形式.它允许多个不相关(无亲缘关系)的进程去访问同一部分逻辑内存.如果需要在两个进程之间传输数据,共享内存将是一种效率极高的解决方案.一旦这样的内存区映 ...

  9. 阿里云修改centos7主机名

    为了玩Docker,买个阿里云主机也是够拼的了. [root@iZ284olvkmjZ ~]# 不过主机名中怎么好DT,无奈,修改. 我们需要的是永久生效,阿里云提供了两种方法: 方法(1). 输入h ...

  10. 从性能角度分析一下String,List,Map

    使用String.subString()方法的时候注意内存溢出的问题 public static void testH() { List<String> strings = new Arr ...