]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/tuple.hh
c88f1935adf71375fcd58a1c7ac3692c7151eb78
[lilypond.git] / flower / include / tuple.hh
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2006--2012 Han-Wen Nienhuys <hanwen@lilypond.org>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef TUPLE_HH
21 #define TUPLE_HH
22
23 template<class T, int N>
24 struct Tuple
25 {
26   T t_array[N];
27   Tuple ()
28   {
29   }
30
31   Tuple (T const *src)
32   {
33     for (int i = 0; i < N; i++)
34       t_array[i] = src[i];
35   }
36 };
37
38 template<class K>
39 struct Tuple2 : public Tuple<K, 2>
40 {
41   Tuple2 ()
42   {
43
44   }
45
46   Tuple2 (K a, K b)
47   {
48     Tuple<K, 2> *p (this);       //  ugr.
49
50     p->t_array[0] = a;
51     p->t_array[1] = b;
52   }
53 };
54
55 template<class T, int N>
56 inline bool
57 operator <(Tuple<T, N> const &t1,
58            Tuple<T, N> const &t2)
59 {
60   for (int i = 0; i < N; i++)
61     {
62       if (t1.t_array[i] > t2.t_array[i])
63         return false;
64       if (t1.t_array[i] < t2.t_array[i])
65         return true;
66     }
67
68   return false;
69 }
70
71 #endif /* TUPLE_HH */