Mozzi  version 2016-12-11-17:03
sound synthesis library for Arduino
meta.h
1 /*
2 http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Int-To-Type
3 Template meta-programming extras.
4 */
5 
6 #ifndef META_H_
7 #define META_H_
8 
9 
19 template <int I>
20 struct Int2Type
21 {
22  enum {
23  value = I };
24 };
25 
26 
27 /*
28 //from http://en.wikibooks.org/wiki/C%2B%2B_Programming/Templates/Template_Meta-Programming#Compile-time_programming
29 
30 //First, the general (unspecialized) template says that factorial<n>::value is given by n*factorial<n-1>::value:
31 template <unsigned n>
32 struct factorial
33 {
34  enum { value = n * factorial<n-1>::value };
35 };
36 
37 
38 //Next, the specialization for zero says that factorial<0>::value evaluates to 1:
39 template <>
40 struct factorial<0>
41 {
42  enum { value = 1 };
43 };
44 
45 
46 //And now some code that "calls" the factorial template at compile-time:
47 // Because calculations are done at compile-time, they can be
48 // used for things such as array sizes, eg.
49 // int array[ factorial<7>::value ];
50 
51 */
52 
53 #endif /* META_H_ */
Enables you to instantiate a template based on an integer value.
Definition: meta.h:20