The Pedigree Project  0.1
Pair.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef KERNEL_UTILITIES_PAIR_H
21 #define KERNEL_UTILITIES_PAIR_H
22 
23 #include "pedigree/kernel/processor/types.h"
24 #include "pedigree/kernel/utilities/template.h"
25 
29 template <class T1, class T2>
30 class Pair
31 {
32  public:
33  Pair() : m_First(), m_Second()
34  {
35  }
36  Pair(const T1 &a, const T2 &b)
37  {
38  m_First = a;
39  m_Second = b;
40  }
41 
42  const T1 &first() const
43  {
44  return m_First;
45  }
46 
47  const T2 &second() const
48  {
49  return m_Second;
50  }
51 
52  private:
53  T1 m_First;
54  T2 m_Second;
55 };
56 
57 template <class T1, class T2>
58 bool operator==(const Pair<T1, T2> &left, const Pair<T1, T2> &right)
59 {
60  return (left.first() == right.first()) && (left.second() == right.second());
61 }
62 
63 template <class T1, class T2>
64 bool operator!=(const Pair<T1, T2> &left, const Pair<T1, T2> &right)
65 {
66  return (left.first() != right.first()) || (left.second() != right.second());
67 }
68 
69 template <class T1, class T2>
70 bool operator<(const Pair<T1, T2> &left, const Pair<T1, T2> &right)
71 {
72  if (left.first() < right.first())
73  {
74  return true;
75  }
76  else if (right.first() < left.first())
77  {
78  return false;
79  }
80 
81  return left.second() < right.second();
82 }
83 
84 template <class T1, class T2>
85 bool operator<=(const Pair<T1, T2> &left, const Pair<T1, T2> &right)
86 {
87  return !(right < left);
88 }
89 
90 template <class T1, class T2>
91 bool operator>(const Pair<T1, T2> &left, const Pair<T1, T2> &right)
92 {
93  return right < left;
94 }
95 
96 template <class T1, class T2>
97 bool operator>=(const Pair<T1, T2> &left, const Pair<T1, T2> &right)
98 {
99  return !(left < right);
100 }
101 
102 template <typename T1, typename T2>
103 Pair<T1, T2> makePair(T1 a, T2 b)
104 {
105  return Pair<T1, T2>(a, b);
106 }
107 
110 #endif
Definition: Pair.h:30
bool operator==(const Iterator< originalT, Struct, FunctionPrev, FunctionNext, T1 > &x1, const Iterator< originalT, Struct, FunctionPrev, FunctionNext, T2 > &x2)
Definition: Iterator.h:326
bool operator!=(const T1 &x1, const T2 &x2)
Global != operator for types with overloaded == operator.
Definition: template.h:32