Home | History | Annotate | Download | only in stl
      1 /*
      2  *
      3  * Copyright (c) 1994
      4  * Hewlett-Packard Company
      5  *
      6  * Copyright (c) 1996,1997
      7  * Silicon Graphics Computer Systems, Inc.
      8  *
      9  * Copyright (c) 1997
     10  * Moscow Center for SPARC Technology
     11  *
     12  * Copyright (c) 1999
     13  * Boris Fomitchev
     14  *
     15  * This material is provided "as is", with absolutely no warranty expressed
     16  * or implied. Any use is at your own risk.
     17  *
     18  * Permission to use or copy this software for any purpose is hereby granted
     19  * without fee, provided the above notices are retained on all copies.
     20  * Permission to modify the code and to distribute modified code is granted,
     21  * provided the above notices are retained, and a notice that the code was
     22  * modified is included with the above copyright notice.
     23  *
     24  */
     25 
     26 
     27 /* NOTE: This is an internal header file, included by other STL headers.
     28  *   You should not attempt to use it directly.
     29  */
     30 
     31 #ifndef _STLP_INTERNAL_PAIR_H
     32 #define _STLP_INTERNAL_PAIR_H
     33 
     34 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
     35 #  ifndef _STLP_TYPE_TRAITS_H
     36 #    include <stl/type_traits.h>
     37 #  endif
     38 
     39 #  if !defined (_STLP_MOVE_CONSTRUCT_FWK_H) && !defined (_STLP_NO_MOVE_SEMANTIC)
     40 #    include <stl/_move_construct_fwk.h>
     41 #  endif
     42 #endif
     43 
     44 _STLP_BEGIN_NAMESPACE
     45 
     46 #if defined (__ANDROID__)
     47 /* Android has stl_pair.h, prevent using it by defining the header guard. */
     48 #  define __SGI_STL_INTERNAL_PAIR_H
     49 #endif
     50 template <class _T1, class _T2>
     51 struct pair {
     52   typedef _T1 first_type;
     53   typedef _T2 second_type;
     54 
     55   _T1 first;
     56   _T2 second;
     57 #if defined (_STLP_CONST_CONSTRUCTOR_BUG)
     58   pair() {}
     59 #else
     60   pair() : first(_T1()), second(_T2()) {}
     61 #endif
     62   pair(const _T1& __a, const _T2& __b) : first(__a), second(__b) {}
     63 
     64 #if defined (_STLP_MEMBER_TEMPLATES)
     65   template <class _U1, class _U2>
     66   pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {}
     67 
     68   pair(const pair<_T1,_T2>& __o) : first(__o.first), second(__o.second) {}
     69 #endif
     70 
     71 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && !defined (_STLP_NO_MOVE_SEMANTIC)
     72   pair(__move_source<pair<_T1, _T2> > src) : first(_STLP_PRIV _AsMoveSource(src.get().first)),
     73                                              second(_STLP_PRIV _AsMoveSource(src.get().second))
     74   {}
     75 #endif
     76 
     77   __TRIVIAL_DESTRUCTOR(pair)
     78 };
     79 
     80 template <class _T1, class _T2>
     81 inline bool _STLP_CALL operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
     82 { return __x.first == __y.first && __x.second == __y.second; }
     83 
     84 template <class _T1, class _T2>
     85 inline bool _STLP_CALL operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
     86   return __x.first < __y.first ||
     87          (!(__y.first < __x.first) && __x.second < __y.second);
     88 }
     89 
     90 #if defined (_STLP_USE_SEPARATE_RELOPS_NAMESPACE)
     91 template <class _T1, class _T2>
     92 inline bool _STLP_CALL operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
     93 { return !(__x == __y); }
     94 
     95 template <class _T1, class _T2>
     96 inline bool _STLP_CALL operator>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
     97 { return __y < __x; }
     98 
     99 template <class _T1, class _T2>
    100 inline bool _STLP_CALL operator<=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
    101 { return !(__y < __x); }
    102 
    103 template <class _T1, class _T2>
    104 inline bool _STLP_CALL operator>=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
    105 { return !(__x < __y); }
    106 #endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
    107 
    108 #if defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) && !defined (_STLP_NO_EXTENSIONS)
    109 template <class _T1, class _T2, int _Sz>
    110 inline pair<_T1, _T2 const*> make_pair(_T1 const& __x,
    111                                        _T2 const (&__y)[_Sz])
    112 { return pair<_T1, _T2 const*>(__x, static_cast<_T2 const*>(__y)); }
    113 
    114 template <class _T1, class _T2, int _Sz>
    115 inline pair<_T1 const*, _T2> make_pair(_T1 const (&__x)[_Sz],
    116                                        _T2 const& __y)
    117 { return pair<_T1 const*, _T2>(static_cast<_T1 const*>(__x), __y); }
    118 
    119 template <class _T1, class _T2, int _Sz1, int _Sz2>
    120 inline pair<_T1 const*, _T2 const*> make_pair(_T1 const (&__x)[_Sz1],
    121                                               _T2 const (&__y)[_Sz2]) {
    122   return pair<_T1 const*, _T2 const*>(static_cast<_T1 const*>(__x),
    123                                       static_cast<_T2 const*>(__y));
    124 }
    125 #endif
    126 
    127 template <class _T1, class _T2>
    128 inline pair<_T1, _T2> _STLP_CALL make_pair(_T1 __x, _T2 __y)
    129 { return pair<_T1, _T2>(__x, __y); }
    130 
    131 _STLP_END_NAMESPACE
    132 
    133 #if defined (_STLP_USE_NAMESPACES) || !defined (_STLP_USE_SEPARATE_RELOPS_NAMESPACE)
    134 _STLP_BEGIN_RELOPS_NAMESPACE
    135 
    136 template <class _Tp>
    137 inline bool _STLP_CALL operator!=(const _Tp& __x, const _Tp& __y)
    138 { return !(__x == __y); }
    139 
    140 template <class _Tp>
    141 inline bool _STLP_CALL operator>(const _Tp& __x, const _Tp& __y)
    142 { return __y < __x; }
    143 
    144 template <class _Tp>
    145 inline bool _STLP_CALL operator<=(const _Tp& __x, const _Tp& __y)
    146 { return !(__y < __x); }
    147 
    148 template <class _Tp>
    149 inline bool _STLP_CALL  operator>=(const _Tp& __x, const _Tp& __y)
    150 { return !(__x < __y); }
    151 
    152 _STLP_END_RELOPS_NAMESPACE
    153 #endif
    154 
    155 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
    156 _STLP_BEGIN_NAMESPACE
    157 
    158 template <class _T1, class _T2>
    159 struct __type_traits<pair<_T1, _T2> > {
    160   typedef __type_traits<_T1> _T1Traits;
    161   typedef __type_traits<_T2> _T2Traits;
    162   typedef typename _Land2<typename _T1Traits::has_trivial_default_constructor,
    163                           typename _T2Traits::has_trivial_default_constructor>::_Ret has_trivial_default_constructor;
    164   typedef typename _Land2<typename _T1Traits::has_trivial_copy_constructor,
    165                           typename _T2Traits::has_trivial_copy_constructor>::_Ret has_trivial_copy_constructor;
    166   typedef typename _Land2<typename _T1Traits::has_trivial_assignment_operator,
    167                           typename _T2Traits::has_trivial_assignment_operator>::_Ret has_trivial_assignment_operator;
    168   typedef typename _Land2<typename _T1Traits::has_trivial_destructor,
    169                           typename _T2Traits::has_trivial_destructor>::_Ret has_trivial_destructor;
    170   typedef __false_type is_POD_type;
    171 };
    172 
    173 #  if !defined (_STLP_NO_MOVE_SEMANTIC)
    174 template <class _T1, class _T2>
    175 struct __move_traits<pair<_T1, _T2> >
    176   : _STLP_PRIV __move_traits_help1<_T1, _T2> {};
    177 #  endif
    178 
    179 _STLP_END_NAMESPACE
    180 #endif
    181 
    182 #endif /* _STLP_INTERNAL_PAIR_H */
    183 
    184 // Local Variables:
    185 // mode:C++
    186 // End:
    187