Pair.h
Go to the documentation of this file.
1#ifndef MiscLib__PAIR_HEADER__
2#define MiscLib__PAIR_HEADER__
3#include <utility>
4
5namespace MiscLib
6{
7 template <class FirstT, class SecondT>
8 struct Pair
9 {
10 typedef FirstT FirstType;
11 typedef SecondT SecondType;
12
14 {
15 }
16
18 {
19 }
20
21 Pair(const std::pair<FirstType, SecondType>& p) : first(p.first), second(p.second)
22 {
23 }
24
26 operator=(const std::pair<FirstType, SecondType>& p)
27 {
28 first = p.first;
29 second = p.second;
30 }
31
34 };
35
36 template <class FirstT>
37 struct Pair<FirstT, FirstT>
38 {
39 typedef FirstT FirstType;
42
44 {
45 }
46
48 {
49 }
50
51 Pair(std::pair<FirstType, SecondType>& p) : first(p.first), second(p.second)
52 {
53 }
54
56 operator=(const std::pair<FirstType, SecondType>& p)
57 {
58 first = p.first;
59 second = p.second;
60 }
61
62 operator FirstType*()
63 {
64 return &first;
65 }
66
67 operator const FirstType*() const
68 {
69 return &first;
70 }
71 };
72
73 template <class FirstT, class SecondT>
74 Pair<FirstT, SecondT>
75 MakePair(FirstT& first, SecondT& second)
76 {
77 return Pair<FirstT, SecondT>(first, second);
78 }
79}; // namespace MiscLib
80
81#endif
Pair< FirstT, SecondT > MakePair(FirstT &first, SecondT &second)
Definition Pair.h:75
Pair(FirstType &f, SecondType &s)
Definition Pair.h:47
Pair(std::pair< FirstType, SecondType > &p)
Definition Pair.h:51
Pair< FirstType, SecondType > & operator=(const std::pair< FirstType, SecondType > &p)
Definition Pair.h:56
Pair(const std::pair< FirstType, SecondType > &p)
Definition Pair.h:21
FirstT FirstType
Definition Pair.h:10
Pair(FirstType &f, SecondType &s)
Definition Pair.h:17
Pair< FirstType, SecondType > & operator=(const std::pair< FirstType, SecondType > &p)
Definition Pair.h:26
SecondType second
Definition Pair.h:33
FirstType first
Definition Pair.h:32
SecondT SecondType
Definition Pair.h:11