Click
Loading...
Searching...
No Matches
pair.hh
1// -*- c-basic-offset: 4 -*-
2#ifndef CLICK_PAIR_HH
3#define CLICK_PAIR_HH
4#include <click/hashcode.hh>
6CLICK_DECLS
7
8template <class T, class U>
9struct Pair {
10
11 typedef T first_type;
12 typedef U second_type;
13 typedef T key_type;
14 typedef const T &key_const_reference;
15
16 T first;
17 U second;
18
19 inline Pair()
20 : first(), second() {
21 }
22
23 inline Pair(typename fast_argument<T>::type t, const uninitialized_type &unused)
24 : first(t), second(U(unused)) {
25 }
26
27 inline Pair(typename fast_argument<T>::type t,
28 typename fast_argument<U>::type u)
29 : first(t), second(u) {
30 }
31
32 inline Pair(const Pair<T, U> &p)
33 : first(p.first), second(p.second) {
34 }
35
36 template <typename V, typename W>
37 inline Pair(const Pair<V, W> &p)
38 : first(p.first), second(p.second) {
39 }
40
41 typedef hashcode_t (Pair<T, U>::*unspecified_bool_type)() const;
42 inline operator unspecified_bool_type() const {
43 return first || second ? &Pair<T, U>::hashcode : 0;
44 }
45
46 inline const T &hashkey() const {
47 return first;
48 }
49
50 inline hashcode_t hashcode() const;
51
52 template <typename V, typename W>
53 Pair<T, U> &operator=(const Pair<V, W> &p) {
54 first = p.first;
55 second = p.second;
56 return *this;
57 }
58
59};
60
61template <class T, class U>
62inline bool operator==(const Pair<T, U> &a, const Pair<T, U> &b)
63{
64 return a.first == b.first && a.second == b.second;
65}
66
67template <class T, class U>
68inline bool operator!=(const Pair<T, U> &a, const Pair<T, U> &b)
69{
70 return a.first != b.first || a.second != b.second;
71}
72
73template <class T, class U>
74inline bool operator<(const Pair<T, U> &a, const Pair<T, U> &b)
75{
76 return a.first < b.first
77 || (!(b.first < a.first) && a.second < b.second);
78}
79
80template <class T, class U>
81inline hashcode_t Pair<T, U>::hashcode() const
82{
83 return (CLICK_NAME(hashcode)(first) << 7) ^ CLICK_NAME(hashcode)(second);
84}
85
86template <class T, class U>
87inline Pair<T, U> make_pair(T t, U u)
88{
89 return Pair<T, U>(t, u);
90}
91
92CLICK_ENDDECLS
93#endif
Template defining a fast argument type for objects of type T.
Definition type_traits.hh:148
Type traits structures.