Mozzi
version v1.1.0
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
10
/** @ingroup util
11
Enables you to instantiate a template based on an integer value.
12
For example, this is used in StateVariable.h to choose a different next()
13
function for each kind of filter, LOWPASS, BANDPASS, HIGHPASS or NOTCH, which are simple
14
integer values 0,1,2,3 provided to the StateVariable template on instantiation.
15
Fantastic!
16
It's in C++11, but not yet available in avr-gcc.
17
See "c++ enable_if"
18
*/
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_ */
Int2Type
Enables you to instantiate a template based on an integer value.
Definition:
meta.h:20
meta.h
Generated on Thu Mar 16 2023 14:01:35 for Mozzi by
1.8.14