2 // Copyright (C) 2008 by Martin Moracek
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Comparable pair classes, based on SGI implementation of std::pair class.
29 template <typename T
, typename U
>
33 typedef U second_type
;
41 cpair() : first(), second() {}
42 cpair(const T
& a
, const U
& b
) : first(a
), second(b
) {}
44 template <typename V1
, typename V2
>
45 cpair(const cpair
<V1
, V2
> & p
) : first(p
.first
), second(p
.second
) {}
47 // also include copy constructors for equivalent std::pair
48 template <typename V1
, typename V2
>
49 cpair(const std::pair
<V1
, V2
> & p
) : first(p
.first
), second(p
.second
) {}
53 template <typename T
, typename U
>
54 inline bool operator == (const cpair
<T
, U
> & l
, const cpair
<T
, U
> & r
)
56 return l
.first
== r
.first
&& l
.second
== r
.second
;
59 template <typename T
, typename U
>
60 inline bool operator == (const cpair
<T
, U
> & l
, const std::pair
<T
, U
> & r
)
62 return l
.first
== r
.first
&& l
.second
== r
.second
;
65 template <typename T
, typename U
>
66 inline bool operator == (const std::pair
<T
, U
> & l
, const cpair
<T
, U
> & r
)
68 return l
.first
== r
.first
&& l
.second
== r
.second
;
72 template <typename T
, typename U
>
73 inline bool operator != (const cpair
<T
, U
> & l
, const cpair
<T
, U
> & r
)
78 template <typename T
, typename U
>
79 inline bool operator != (const cpair
<T
, U
> & l
, const std::pair
<T
, U
> & r
)
84 template <typename T
, typename U
>
85 inline bool operator != (const std::pair
<T
, U
> & l
, const cpair
<T
, U
> & r
)
91 template <typename T
, typename U
>
92 inline bool operator < (const cpair
<T
, U
> & l
, const cpair
<T
, U
> & r
)
94 return l
.first
< r
.first
;
97 template <typename T
, typename U
>
98 inline bool operator < (const T
& l
, const cpair
<T
, U
> & r
)
103 template <typename T
, typename U
>
104 inline bool operator < (const cpair
<T
, U
> & l
, const T
& r
)
109 // A convenience wrapper for creating a pair from two objects.
110 // template <typename T, typename U>
111 // inline cpair<T, U> make_cpair(T l, U r)
113 // return cpair<T, U>(l, r);