RSC  0.17.1
PairWorkaround.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is part of the RSC project
4  *
5  * Copyright (C) 2010, 2011 Jan Moringen
6  *
7  * This file may be licensed under the terms of the
8  * GNU Lesser General Public License Version 3 (the ``LGPL''),
9  * or (at your option) any later version.
10  *
11  * Software distributed under the License is distributed
12  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13  * express or implied. See the LGPL for the specific language
14  * governing rights and limitations.
15  *
16  * You should have received a copy of the LGPL along with this
17  * program. If not, go to http://www.gnu.org/licenses/lgpl.html
18  * or write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  * The development of this software was supported by:
22  * CoR-Lab, Research Institute for Cognition and Robotics
23  * Bielefeld University
24  *
25  * ============================================================ */
26 
27 #pragma once
28 
29 #include <boost/type_traits.hpp>
30 
31 namespace rsc {
32 namespace patterns {
33 namespace detail {
34 
36 template<class _T1, class _T2>
37 struct pair {
38  typedef _T1 first_type;
39  typedef _T2 second_type;
40 
41  _T1 first;
42  _T2 second;
43 
44  // _GLIBCXX_RESOLVE_LIB_DEFECTS
45  // 265. std::pair::pair() effects overly restrictive
48  pair() :
49  first(), second() {
50  }
51 
53  pair(typename boost::remove_reference<_T1>::type& __a,
54  typename boost::remove_reference<_T2>::type& __b) :
55  first(__a), second(__b) {
56  }
57 
59  template<class _U1, class _U2>
60  pair(const pair<_U1, _U2>& __p) :
61  first(__p.first), second(__p.second) {
62  }
63 };
64 
66 template<class _T1, class _T2>
67 inline bool operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
68  return __x.first == __y.first && __x.second == __y.second;
69 }
70 
72 template<class _T1, class _T2>
73 inline bool operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
74  return __x.first < __y.first || (!(__y.first < __x.first) && __x.second
75  < __y.second);
76 }
77 
79 template<class _T1, class _T2>
80 inline bool operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
81  return !(__x == __y);
82 }
83 
85 template<class _T1, class _T2>
86 inline bool operator>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
87  return __y < __x;
88 }
89 
91 template<class _T1, class _T2>
92 inline bool operator<=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
93  return !(__y < __x);
94 }
95 
97 template<class _T1, class _T2>
98 inline bool operator>=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
99  return !(__x < __y);
100 }
101 
112 // _GLIBCXX_RESOLVE_LIB_DEFECTS
113 // 181. make_pair() unintended behavior
114 template<class _T1, class _T2>
115 inline pair<_T1, _T2> make_pair(_T1 __x, _T2 __y) {
116  return pair<_T1, _T2> (__x, __y);
117 }
118 
119 }
120 }
121 }
pair(const pair< _U1, _U2 > &__p)
There is also a templated copy ctor for the pair class itself.
pair< _T1, _T2 > make_pair(_T1 __x, _T2 __y)
A convenience wrapper for creating a pair from two objects.
_T2 second_type
second_type is the second bound type
_T2 second
second is a copy of the second object
_T1 first_type
first_type is the first bound type
bool operator>(const pair< _T1, _T2 > &__x, const pair< _T1, _T2 > &__y)
Uses operator< to find the result.
pair(typename boost::remove_reference< _T1 >::type &__a, typename boost::remove_reference< _T2 >::type &__b)
Two objects may be passed to a pair constructor to be copied.
_T1 first
first is a copy of the first object
bool operator>=(const pair< _T1, _T2 > &__x, const pair< _T1, _T2 > &__y)
Uses operator< to find the result.
pair holds two objects of arbitrary type.
bool operator==(const pair< _T1, _T2 > &__x, const pair< _T1, _T2 > &__y)
Two pairs of the same type are equal iff their members are equal.
bool operator!=(const pair< _T1, _T2 > &__x, const pair< _T1, _T2 > &__y)
Uses operator== to find the result.
pair()
The default constructor creates first and second using their respective default constructors.