Elm  1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Pair.h
1 /*
2  * $Id$
3  * Copyright (c) 2006 - IRIT-UPS <casse@irit.fr>
4  *
5  * elm/util/Pair.h -- interface of Pair class.
6  */
7 #ifndef ELM_UTIL_PAIR_H
8 #define ELM_UTIL_PAIR_H
9 
10 namespace elm {
11 
12 namespace io { class Output; }
13 
14 // Pair class
15 template <class T1, class T2>
16 class Pair {
17 public:
18  T1 fst;
19  T2 snd;
20  inline Pair(void) { }
21  inline Pair(const T1& _fst, const T2& _snd): fst(_fst), snd(_snd) { }
22  inline Pair(const Pair<T1, T2>& pair): fst(pair.fst), snd(pair.snd) { }
23  inline Pair<T1, T2>& operator=(const Pair<T1, T2>& pair) { fst = pair.fst; snd = pair.snd; return *this; }
24  inline bool operator==(const Pair<T1, T2>& pair) const { return ((fst== pair.fst) && (snd == pair.snd)); }
25 };
26 
27 
28 // RefPair class
29 template <class T1, class T2>
30 class RefPair {
31 public:
32  inline RefPair(T1& r1, T2& r2): v1(r1), v2(r2) { }
33  RefPair<T1, T2>& operator=(const Pair<T1, T2>& p) { v1 = p.fst; v2 = p.snd; return *this; }
34 private:
35  T1& v1;
36  T2& v2;
37 };
38 
39 
40 // Shortcuts
41 template <class T1, class T2> inline Pair<T1, T2> pair(const T1& v1, const T2& v2) { return Pair<T1, T2>(v1, v2); }
42 template <class T1, class T2> io::Output& operator<<(io::Output& out, Pair<T1, T2>& p) { out << p.fst << ", " << p.snd; return out; }
43 template <class T1, class T2> inline RefPair<T1, T2> let(T1& v1, T2& v2) { return RefPair<T1, T2>(v1, v2); }
44 
45 } // elm
46 
47 #endif /* ELM_UTIL_PAIR_H */
RefPair(T1 &r1, T2 &r2)
Definition: Pair.h:32
Pair< T1, T2 > & operator=(const Pair< T1, T2 > &pair)
Definition: Pair.h:23
Definition: Output.h:161
Pair< T1, T2 > pair(const T1 &v1, const T2 &v2)
Definition: Pair.h:41
Pair(void)
Definition: Pair.h:20
T1 fst
Definition: Pair.h:18
Pair(const Pair< T1, T2 > &pair)
Definition: Pair.h:22
RefPair< T1, T2 > & operator=(const Pair< T1, T2 > &p)
Definition: Pair.h:33
sys::SystemOutStream & out
Definition: system_SystemIO.cpp:101
Pair(const T1 &_fst, const T2 &_snd)
Definition: Pair.h:21
T2 snd
Definition: Pair.h:19
bool operator==(const Pair< T1, T2 > &pair) const
Definition: Pair.h:24
RefPair< T1, T2 > let(T1 &v1, T2 &v2)
Definition: Pair.h:43
Definition: Pair.h:16
Definition: Pair.h:30