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. Linux下tar解压缩命令

    1.打包命令: 命令格式:tar  -zcvf   压缩文件名.tar.gz   被压缩文件名 可先切换到当前目录下.压缩文件名和被压缩文件名都可加入路径. 2.解包命令: 命令格式:tar  -zx ...

  2. ANDROID版本号号和版本号名称的重要性介绍

    转载请注明出处http://blog.csdn.net/y150481863/article/details/41249159,来自[http://blog.csdn.net/y150481863] ...

  3. KPI、KPA、OKR三者的区别

    KPI.KPA或者OKR并不是水火不相容有你无我的概念,针对不对的业务状态.管理模式应该有所选择.以下是介绍它们之间的区别. 什么是KPI关键绩效指标 KPI(key performance indi ...

  4. 自动更新GeoIP数据库

    #!/bin/bash if [ ! -d /usr/local/share/GeoIP ];then mkdir /usr/local/share/GeoIP fi if [ ! -d /usr/l ...

  5. 摇一摇js代码

    init(); var SHAKE_THRESHOLD = 3000; var last_update = 0; var x = y = z = last_x = last_y = last_z = ...

  6. [php][随机数]曲线式的随机

    数学函数原型: y = max / (x ^ 2) 函数图像(来自google): y = 100 / x ^ (-2) 其中y为随机结果,max为最大值且max>1,x为随机数, 两个参数: ...

  7. 我的Android进阶之旅------>Android KeyCode列表

    KEYCODE列表 电话键 KEYCODE_CALL 拨号键 5 KEYCODE_ENDCALL 挂机键 6 KEYCODE_HOME 按键Home 3 KEYCODE_MENU 菜单键 82 KEY ...

  8. Django利用form进行显示

    form的显示部分主要分为2部分:1.统一显示(表单里的所有字段): a.{{form.as_table}} b.{{form.as_p}}2.显示部分字段: {{ field.label_tag } ...

  9. ABAP制作密码输入框

    [转自 http://blog.csdn.net/saphome/article/details/6956911] 这几天做一个系统维护的程序,需要用户输入用户名和密码登录.可怎样实现输入密码显示星号 ...

  10. 销售订单、外向交货单、交货 bapi

    转自[http://www.cnblogs.com/elegantok/archive/2009/10/18/1585398.html]***********SALES ORDER INPUT CRE ...