Mozzi  version v2.0
sound synthesis library for Arduino
meta.h
1 /*
2  * meta.h
3  *
4  * This file is part of Mozzi.
5  *
6  * Copyright 2012-2024 Tim Barrass and the Mozzi Team
7  *
8  * Mozzi is licensed under the GNU Lesser General Public Licence (LGPL) Version 2.1 or later.
9  *
10  */
11 
12 /*
13 http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Int-To-Type
14 Template meta-programming extras.
15 */
16 
17 #ifndef META_H_
18 #define META_H_
19 
39 template <int I>
40 struct Int2Type
41 {
42  enum {
43  value = I };
44 };
45 
46 
47 /*
48 //from http://en.wikibooks.org/wiki/C%2B%2B_Programming/Templates/Template_Meta-Programming#Compile-time_programming
49 
50 //First, the general (unspecialized) template says that factorial<n>::value is given by n*factorial<n-1>::value:
51 template <unsigned n>
52 struct factorial
53 {
54  enum { value = n * factorial<n-1>::value };
55 };
56 
57 
58 //Next, the specialization for zero says that factorial<0>::value evaluates to 1:
59 template <>
60 struct factorial<0>
61 {
62  enum { value = 1 };
63 };
64 
65 
66 //And now some code that "calls" the factorial template at compile-time:
67 // Because calculations are done at compile-time, they can be
68 // used for things such as array sizes, eg.
69 // int array[ factorial<7>::value ];
70 
71 */
72 
73 #endif /* META_H_ */
Enables you to instantiate a template based on an integer value.
Definition: meta.h:41