]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/tuple.hh
5f2705b8fab12501a9f615114eb7a32cb7b27e09
[lilypond.git] / flower / include / tuple.hh
1 /*
2   tuple.hh -- declare Tuple
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2006--2007 Han-Wen Nienhuys <hanwen@lilypond.org>
7
8 */
9
10 #ifndef TUPLE_HH
11 #define TUPLE_HH
12
13 template<class T, int N>
14 struct Tuple
15 {
16   T t_array[N];
17   Tuple ()
18   {
19   }
20   
21   Tuple (T const *src)
22   {
23     for (int i = 0; i < N; i++)
24       t_array[i] = src[i];
25   }
26 };
27
28 template<class K>
29 struct Tuple2 : public Tuple<K, 2>
30 {
31   Tuple2 ()
32   {
33
34   }
35   
36   Tuple2 (K a, K b)
37   {
38     Tuple<K,2> *p(this);        //  ugr.
39     
40     p->t_array[0] = a;
41     p->t_array[1] = b;
42   }
43 };
44
45   
46 template<class T, int N>
47 inline bool
48 operator<(Tuple<T, N> const &t1,
49           Tuple<T, N> const &t2)
50 {
51   for (int i = 0; i < N ; i++)
52     {
53       if (t1.t_array[i] > t2.t_array[i])
54         return false;
55       if (t1.t_array[i] < t2.t_array[i])
56         return true;
57     }
58
59   return false;
60 }
61
62 #endif /* TUPLE_HH */