1 | #include <tuple> |
2 | |
3 | template <int Arg> |
4 | class TestObj |
5 | { |
6 | public: |
7 | int getArg() |
8 | { |
9 | return Arg; |
10 | } |
11 | }; |
12 | |
13 | //---------------------------------------------------------------------- |
14 | // Define a template class that we can specialize with an enumeration |
15 | //---------------------------------------------------------------------- |
16 | enum class EnumType |
17 | { |
18 | Member, |
19 | Subclass |
20 | }; |
21 | |
22 | template <EnumType Arg> class EnumTemplate; |
23 | |
24 | //---------------------------------------------------------------------- |
25 | // Specialization for use when "Arg" is "EnumType::Member" |
26 | //---------------------------------------------------------------------- |
27 | template <> |
28 | class EnumTemplate<EnumType::Member> |
29 | { |
30 | public: |
31 | EnumTemplate(int m) : |
32 | m_member(m) |
33 | { |
34 | } |
35 | |
36 | int getMember() const |
37 | { |
38 | return m_member; |
39 | } |
40 | |
41 | protected: |
42 | int m_member; |
43 | }; |
44 | |
45 | //---------------------------------------------------------------------- |
46 | // Specialization for use when "Arg" is "EnumType::Subclass" |
47 | //---------------------------------------------------------------------- |
48 | template <> |
49 | class EnumTemplate<EnumType::Subclass> : |
50 | public EnumTemplate<EnumType::Member> |
51 | { |
52 | public: |
53 | EnumTemplate(int m) : EnumTemplate<EnumType::Member>(m) |
54 | { |
55 | } |
56 | }; |
57 | |
58 | template <typename FLOAT> struct T1 { FLOAT f = 1.5; }; |
59 | template <typename FLOAT> struct T2 { FLOAT f = 2.5; int i = 42; }; |
60 | template <typename FLOAT, template <typename> class ...Args> class C { std::tuple<Args<FLOAT>...> V; }; |
61 | |
62 | int main(int argc, char **argv) |
63 | { |
64 | TestObj<1> testpos; |
65 | TestObj<-1> testneg; |
66 | EnumTemplate<EnumType::Member> member(123); |
67 | EnumTemplate<EnumType::Subclass> subclass(123*2); |
68 | C<float, T1> c1; |
69 | C<double, T1, T2> c2; |
70 | return testpos.getArg() - testneg.getArg() + member.getMember()*2 - subclass.getMember(); // Breakpoint 1 |
71 | } |
72 | |