<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ### 前言 ? ? ?pair在關聯容器中經常被使用,它提供了兩個成員變量first和second,由于pair是一個struct,所以其成員變量的屬性是public。在pair struct中提供了構造函數和拷貝構造函數,同時提供了兩個最基本的操作operator==和operator<重載,其他的操作符重載都是基于前面兩種的變形。本文源碼來自SGI STL中的<stl_pair.h>文件。 ### pair源碼剖析 ~~~ #ifndef __SGI_STL_INTERNAL_PAIR_H #define __SGI_STL_INTERNAL_PAIR_H __STL_BEGIN_NAMESPACE /* pair在關聯容器中使用很廣泛,它是STL的模板類型,可以存儲兩個成員變量 pair采用的是struct結構,struct的成員默認屬性是public */ template <class _T1, class _T2> struct pair { typedef _T1 first_type; typedef _T2 second_type; //pair的兩個成員變量,其屬性是public _T1 first; _T2 second; //以下是構造函數 pair() : first(_T1()), second(_T2()) {} pair(const _T1& __a, const _T2& __b) : first(__a), second(__b) {} #ifdef __STL_MEMBER_TEMPLATES //兼容性的拷貝構造函數 //兼容性是指兩個pair的類型可以不同,但是必須可以轉換 template <class _U1, class _U2> pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {} //注意:用pair初始化另一個pair時,只能通過拷貝構造函數進行,不能通過賦值進行 //因為這里沒有提供operator=操作符的重載 #endif }; //operator==操作符重載 //兩個pair相等時,意味著兩個成員變量都對應相等 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; } //operator<操作符重載 //比較兩個pair時,以第一個成員變量first為主,若第一個成員變量first不能判斷表達式的大小 //則對其第二個成員變量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_ORDER //下面的操作符重載都是基于上面operator<和operator==操作符的. //operator!=,operator>,operator<=,operator>=操作符的重載 template <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); } #endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */ //根據兩個數值,構造一個pair 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源碼剖析》侯捷 《[STL源碼剖析-- stl_pair.h](http://blog.csdn.net/mdl13412/article/details/6643400)》
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看