4 * Hewlett-Packard Company
6 * Copyright (c) 1996,1997
7 * Silicon Graphics Computer Systems, Inc.
10 * Moscow Center for SPARC Technology
15 * This material is provided "as is", with absolutely no warranty expressed
16 * or implied. Any use is at your own risk.
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.
27 /* NOTE: This is an internal header file, included by other STL headers.
28 * You should not attempt to use it directly.
31 #ifndef _STLP_INTERNAL_PAIR_H
32 #define _STLP_INTERNAL_PAIR_H
34 #include <stl/_construct.h>
38 #ifdef _STLP_USE_TRAP_LEAVE
39 template <class _T1, class _T2>
41 typedef _T1 first_type;
42 typedef _T2 second_type;
45 _STLP_StackPusher<_T1> __pusher;
48 // first and second should construct themselves with their default constructors in ANSI order
49 pair() : __pusher(&first) {
53 pair(const _T1& __a, const _T2& __b) : first(__a), __pusher(&first), second(__b) {
57 // undergroud extensions
58 pair(const _T1& __a, __false_type) : first(__a), __pusher(&first), second() {
61 pair(__true_type, const _T2& __a) : first(), __pusher(&first), second(__a) {
65 #if defined (_STLP_MEMBER_TEMPLATES) && !(defined (_STLP_MSVC) && (_STLP_MSVC < 1200))
66 template <class _U1, class _U2>
67 pair(const pair<_U1, _U2>& __p) : first(__p.first), __pusher(&first), second(__p.second) {
71 pair(const pair<_T1,_T2>& __o) : first(__o.first), __pusher(&first), second(__o.second) {
75 __TRIVIAL_DESTRUCTOR(pair)
80 template <class _T1, class _T2>
82 typedef _T1 first_type;
83 typedef _T2 second_type;
87 # if defined (_STLP_CONST_CONSTRUCTOR_BUG)
90 pair() : first(_T1()), second(_T2()) {}
92 pair(const _T1& __a, const _T2& __b) : first(__a), second(__b) {}
94 // undergroud extensions
95 pair(const _T1& __a, __false_type) : first(__a), second() {}
96 pair(const _T2& __a, __true_type) : first(), second(__a) {}
98 #if defined (_STLP_MEMBER_TEMPLATES) && !(defined (_STLP_MSVC) && (_STLP_MSVC < 1200))
99 template <class _U1, class _U2>
100 pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {}
102 pair(const pair<_T1,_T2>& __o) : first(__o.first), second(__o.second) {}
104 __TRIVIAL_DESTRUCTOR(pair)
108 template <class _T1, class _T2>
109 inline bool _STLP_CALL operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
111 return __x.first == __y.first && __x.second == __y.second;
114 template <class _T1, class _T2>
115 inline bool _STLP_CALL operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
117 return __x.first < __y.first ||
118 (!(__y.first < __x.first) && __x.second < __y.second);
121 #ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
123 template <class _T1, class _T2>
124 inline bool _STLP_CALL operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
125 return !(__x == __y);
128 template <class _T1, class _T2>
129 inline bool _STLP_CALL operator>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
133 template <class _T1, class _T2>
134 inline bool _STLP_CALL operator<=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
138 template <class _T1, class _T2>
139 inline bool _STLP_CALL operator>=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
143 #endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
146 #if defined(_STLP_FUNCTION_TMPL_PARTIAL_ORDER) && ! defined (_STLP_NO_EXTENSIONS) && ! defined (__BORLANDC__) && ! defined (__DMC__)
147 template <class _T1, class _T2, int _Sz>
148 inline pair<_T1, _T2 const*> make_pair(_T1 const& __x,
149 _T2 const (&__y)[_Sz])
151 return pair<_T1, _T2 const*>(__x, static_cast<_T2 const*>(__y));
154 template <class _T1, class _T2, int _Sz>
155 inline pair<_T1 const*, _T2> make_pair(_T1 const (&__x)[_Sz],
158 return pair<_T1 const*, _T2>(static_cast<_T1 const*>(__x), __y);
161 template <class _T1, class _T2, int _Sz1, int _Sz2>
162 inline pair<_T1 const*, _T2 const*> make_pair(_T1 const (&__x)[_Sz1],
163 _T2 const (&__y)[_Sz2])
165 return pair<_T1 const*, _T2 const*>(static_cast<_T1 const*>(__x),
166 static_cast<_T2 const*>(__y));
170 template <class _T1, class _T2>
171 inline pair<_T1, _T2> _STLP_CALL make_pair(const _T1& __x, const _T2& __y)
173 return pair<_T1, _T2>(__x, __y);
179 # if defined (_STLP_USE_NAMESPACES) || ! defined (_STLP_USE_SEPARATE_RELOPS_NAMESPACE)
180 _STLP_BEGIN_RELOPS_NAMESPACE
183 inline bool _STLP_CALL operator!=(const _Tp& __x, const _Tp& __y) {
184 return !(__x == __y);
188 inline bool _STLP_CALL operator>(const _Tp& __x, const _Tp& __y) {
193 inline bool _STLP_CALL operator<=(const _Tp& __x, const _Tp& __y) {
198 inline bool _STLP_CALL operator>=(const _Tp& __x, const _Tp& __y) {
202 _STLP_END_RELOPS_NAMESPACE
206 #endif /* _STLP_INTERNAL_PAIR_H */