Waarom mag dit eigenlijk niet?
Erg vreemd allemaal. Wordt hier naar gekeken voor de nieuwe C++ standaard? Mijn oplossing is nu zo lang maar dit:
Maar ik vind het eigenlijk best wel lelijk. Is er nog een andere oplossing? Waarom mag ik wel een partial specialization doen, maar geen volledige? Rationale?
C++:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| template <typename T> class Foo { public: template <int N> void bar() {} template <> void bar<0>() {} // not allowed template <int N, int M> void f() {} template <int M> void f<0, M>() {} // impossible for members! template <int N> struct X {}; template <> struct X<0>{}; // not allowed template <int N, int M> struct X{}; template <int M> struct X<0, M>{}; // this IS allowed! template <int N> void outofclass() {} }; template <typename T> template <> void Foo<T>::outofclass<0>() {} // outer template not fully specialized: not allowed. This would be fine if Foo was not a class template. |
Erg vreemd allemaal. Wordt hier naar gekeken voor de nieuwe C++ standaard? Mijn oplossing is nu zo lang maar dit:
C++:
1
2
3
4
5
6
7
8
9
10
11
12
| template <typename T> class Foo { private: template <int N, int Dummy> struct Internal { static void f() {} }; template <int Dummy> struct Internal<0, Dummy> { static void f() {} }; public: void x() { Internal<5, 0>::f();} }; |
Maar ik vind het eigenlijk best wel lelijk. Is er nog een andere oplossing? Waarom mag ik wel een partial specialization doen, maar geen volledige? Rationale?
[ Voor 9% gewijzigd door Zoijar op 08-09-2005 10:48 ]