Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
EXPLICIT_MEMBER_SPECIALIZATION.cpp
Go to the documentation of this file.
1// checking for explicit member specialization
2
3
25struct A
26{
27 int i_;
28
29 // no default ctor declared to exercise the compiler's ability
30 // distinguish between a declaration of an explicir member
31 // specialization and a definition of the same (see below)
32 A (int i): i_ (i) { }
33};
34
35template <class T>
36struct B {
37
38 int foo () { return a.i_; }
39 int bar ();
40
41 static A a;
42};
43
44// declare explicit specialization of template members
45template <> inline int B<int>::foo ();
46template <> int B<int>::bar ();
47
48// make sure this is taken as a declaration and not a definition
49// as, for example, with SunPro 5.5 (see bug #411)
50template <> A B<int>::a;
51
52// define explicit specialization of template members
53template <> inline int B<int>::foo () { return 1; }
54template <> int B<int>::bar () { return 1; }
55template <> A B<int>::a (1);
56
57// define members of the primary template
58template <class T> int B<T>::bar () { return foo (); }
59template <class T> A B<T>::a (0);
60
61int main ()
62{
63 B<char> bc;
64 bc.foo ();
65 bc.bar ();
66
67 B<int> bi;
68
69 int status = 0;
70
71 if (1 != bi.foo ())
72 status |= 1;
73
74 if (1 != bi.bar ())
75 status |= 2;
76
77 if (1 != bi.a.i_)
78 status |= 4;
79
80 return status;
81}
#define i
Definition 17.names.cpp:126
#define i_
Definition 17.names.cpp:180
#define a
Definition 17.names.cpp:109
#define foo(buf, s,...)