_pair.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. /* NOTE: This is an internal header file, included by other STL headers.
  26. * You should not attempt to use it directly.
  27. */
  28. #ifndef _STLP_INTERNAL_PAIR_H
  29. #define _STLP_INTERNAL_PAIR_H
  30. #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
  31. # ifndef _STLP_TYPE_TRAITS_H
  32. # include <stl/type_traits.h>
  33. # endif
  34. # if !defined (_STLP_MOVE_CONSTRUCT_FWK_H) && !defined (_STLP_NO_MOVE_SEMANTIC)
  35. # include <stl/_move_construct_fwk.h>
  36. # endif
  37. #endif
  38. _STLP_BEGIN_NAMESPACE
  39. template <class _T1, class _T2>
  40. struct pair {
  41. typedef _T1 first_type;
  42. typedef _T2 second_type;
  43. _T1 first;
  44. _T2 second;
  45. #if defined (_STLP_CONST_CONSTRUCTOR_BUG)
  46. pair() {}
  47. #else
  48. pair() : first(_T1()), second(_T2()) {}
  49. #endif
  50. pair(const _T1& __a, const _T2& __b) : first(__a), second(__b) {}
  51. #if defined (_STLP_MEMBER_TEMPLATES)
  52. template <class _U1, class _U2>
  53. pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {}
  54. pair(const pair<_T1,_T2>& __o) : first(__o.first), second(__o.second) {}
  55. #endif
  56. #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && !defined (_STLP_NO_MOVE_SEMANTIC)
  57. pair(__move_source<pair<_T1, _T2> > src) : first(_STLP_PRIV _AsMoveSource(src.get().first)),
  58. second(_STLP_PRIV _AsMoveSource(src.get().second))
  59. {}
  60. #endif
  61. __TRIVIAL_DESTRUCTOR(pair)
  62. };
  63. template <class _T1, class _T2>
  64. inline bool _STLP_CALL operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
  65. { return __x.first == __y.first && __x.second == __y.second; }
  66. template <class _T1, class _T2>
  67. inline bool _STLP_CALL operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
  68. return __x.first < __y.first ||
  69. (!(__y.first < __x.first) && __x.second < __y.second);
  70. }
  71. #if defined (_STLP_USE_SEPARATE_RELOPS_NAMESPACE)
  72. template <class _T1, class _T2>
  73. inline bool _STLP_CALL operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
  74. { return !(__x == __y); }
  75. template <class _T1, class _T2>
  76. inline bool _STLP_CALL operator>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
  77. { return __y < __x; }
  78. template <class _T1, class _T2>
  79. inline bool _STLP_CALL operator<=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
  80. { return !(__y < __x); }
  81. template <class _T1, class _T2>
  82. inline bool _STLP_CALL operator>=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
  83. { return !(__x < __y); }
  84. #endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
  85. #if defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) && !defined (_STLP_NO_EXTENSIONS)
  86. template <class _T1, class _T2, int _Sz>
  87. inline pair<_T1, _T2 const*> make_pair(_T1 const& __x,
  88. _T2 const (&__y)[_Sz])
  89. { return pair<_T1, _T2 const*>(__x, static_cast<_T2 const*>(__y)); }
  90. template <class _T1, class _T2, int _Sz>
  91. inline pair<_T1 const*, _T2> make_pair(_T1 const (&__x)[_Sz],
  92. _T2 const& __y)
  93. { return pair<_T1 const*, _T2>(static_cast<_T1 const*>(__x), __y); }
  94. template <class _T1, class _T2, int _Sz1, int _Sz2>
  95. inline pair<_T1 const*, _T2 const*> make_pair(_T1 const (&__x)[_Sz1],
  96. _T2 const (&__y)[_Sz2]) {
  97. return pair<_T1 const*, _T2 const*>(static_cast<_T1 const*>(__x),
  98. static_cast<_T2 const*>(__y));
  99. }
  100. #endif
  101. template <class _T1, class _T2>
  102. inline pair<_T1, _T2> _STLP_CALL make_pair(_T1 __x, _T2 __y)
  103. { return pair<_T1, _T2>(__x, __y); }
  104. _STLP_END_NAMESPACE
  105. #if defined (_STLP_USE_NAMESPACES) || !defined (_STLP_USE_SEPARATE_RELOPS_NAMESPACE)
  106. _STLP_BEGIN_RELOPS_NAMESPACE
  107. template <class _Tp>
  108. inline bool _STLP_CALL operator!=(const _Tp& __x, const _Tp& __y)
  109. { return !(__x == __y); }
  110. template <class _Tp>
  111. inline bool _STLP_CALL operator>(const _Tp& __x, const _Tp& __y)
  112. { return __y < __x; }
  113. template <class _Tp>
  114. inline bool _STLP_CALL operator<=(const _Tp& __x, const _Tp& __y)
  115. { return !(__y < __x); }
  116. template <class _Tp>
  117. inline bool _STLP_CALL operator>=(const _Tp& __x, const _Tp& __y)
  118. { return !(__x < __y); }
  119. _STLP_END_RELOPS_NAMESPACE
  120. #endif
  121. #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
  122. _STLP_BEGIN_NAMESPACE
  123. template <class _T1, class _T2>
  124. struct __type_traits<pair<_T1, _T2> > {
  125. typedef __type_traits<_T1> _T1Traits;
  126. typedef __type_traits<_T2> _T2Traits;
  127. typedef typename _Land2<typename _T1Traits::has_trivial_default_constructor,
  128. typename _T2Traits::has_trivial_default_constructor>::_Ret has_trivial_default_constructor;
  129. typedef typename _Land2<typename _T1Traits::has_trivial_copy_constructor,
  130. typename _T2Traits::has_trivial_copy_constructor>::_Ret has_trivial_copy_constructor;
  131. typedef typename _Land2<typename _T1Traits::has_trivial_assignment_operator,
  132. typename _T2Traits::has_trivial_assignment_operator>::_Ret has_trivial_assignment_operator;
  133. typedef typename _Land2<typename _T1Traits::has_trivial_destructor,
  134. typename _T2Traits::has_trivial_destructor>::_Ret has_trivial_destructor;
  135. typedef __false_type is_POD_type;
  136. };
  137. # if !defined (_STLP_NO_MOVE_SEMANTIC)
  138. template <class _T1, class _T2>
  139. struct __move_traits<pair<_T1, _T2> >
  140. : _STLP_PRIV __move_traits_help1<_T1, _T2> {};
  141. # endif
  142. _STLP_END_NAMESPACE
  143. #endif
  144. #endif /* _STLP_INTERNAL_PAIR_H */
  145. // Local Variables:
  146. // mode:C++
  147. // End: