Initial commit, includes Lua with broken Luabind as a backup for branching purposes
[terrastrategy.git] / include / cpair.h
blobeb56d566a7a90c92e8bf989af1334a997f7aac1d
1 //
2 // Copyright (C) 2008 by Martin Moracek
3 //
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.
8 //
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
19 /**
20 * @file cpair.h
22 * Comparable pair classes, based on SGI implementation of std::pair class.
25 #pragma once
27 #include <utility>
29 template <typename T, typename U>
30 class cpair {
31 public:
32 typedef T first_type;
33 typedef U second_type;
35 public:
36 T first;
37 U second;
39 public:
40 // constructors
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) {}
52 // operator ==
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;
71 // operator !=
72 template <typename T, typename U>
73 inline bool operator != (const cpair<T, U> & l, const cpair<T, U> & r)
75 return !(l == r);
78 template <typename T, typename U>
79 inline bool operator != (const cpair<T, U> & l, const std::pair<T, U> & r)
81 return !(l == r);
84 template <typename T, typename U>
85 inline bool operator != (const std::pair<T, U> & l, const cpair<T, U> & r)
87 return !(l == r);
90 // operator <
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)
100 return l < r.first;
103 template <typename T, typename U>
104 inline bool operator < (const cpair<T, U> & l, const T & r)
106 return l.first < 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)
112 // {
113 // return cpair<T, U>(l, r);
114 // }