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
29template <class T1, class T2>
30class Pair {
31 public:
32 Pair() : m_First(), m_Second() {}
33 Pair(const T1& a, const T2& b) {
34 m_First = a;
35 m_Second = b;
36 }
37
38 const T1& first() const {
39 return m_First;
40 }
41
42 const T2& second() const {
43 return m_Second;
44 }
45
46 private:
47 T1 m_First;
48 T2 m_Second;
49};
50
51template <class T1, class T2>
52bool operator==(const Pair<T1, T2>& left, const Pair<T1, T2>& right) {
53 return (left.first() == right.first()) && (left.second() == right.second());
54}
55
56template <class T1, class T2>
57bool operator!=(const Pair<T1, T2>& left, const Pair<T1, T2>& right) {
58 return (left.first() != right.first()) || (left.second() != right.second());
59}
60
61template <class T1, class T2>
62bool operator<(const Pair<T1, T2>& left, const Pair<T1, T2>& right) {
63 if (left.first() < right.first()) {
64 return true;
65 } else if (right.first() < left.first()) {
66 return false;
67 }
68
69 return left.second() < right.second();
70}
71
72template <class T1, class T2>
73bool operator<=(const Pair<T1, T2>& left, const Pair<T1, T2>& right) {
74 return !(right < left);
75}
76
77template <class T1, class T2>
78bool operator>(const Pair<T1, T2>& left, const Pair<T1, T2>& right) {
79 return right < left;
80}
81
82template <class T1, class T2>
83bool operator>=(const Pair<T1, T2>& left, const Pair<T1, T2>& right) {
84 return !(left < right);
85}
86
87template <typename T1, typename T2>
88Pair<T1, T2> makePair(T1 a, T2 b) {
89 return Pair<T1, T2>(a, b);
90}
91
94#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:256