Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
DUMMY_DEFAULT_ARG.cpp
Go to the documentation of this file.
1// checking for dummy default arguments
2
3
25template <class T>
26T foo (const T* = 0) { return T (); }
27
28template <>
29int foo<int>(const int*) { return 1; }
30
31template <>
32long foo<long>(const long*) { return 2; }
33
34
35struct X { };
36
37template <class T>
38struct A {
39 int i_;
40
41 A (int i): i_ (i) { }
42};
43
44template <class T>
45struct B {
46 int i_;
47
48 B (int i): i_ (i) { }
49};
50
51
52template <class T>
53T bar (const X&, const T* = 0) { return T (); }
54
55template <>
56A<int> bar<A<int> >(const X&, const A<int>*) { return A<int>(1); }
57
58template <>
59B<long> bar<B<long> >(const X&, const B<long>*) { return B<long>(2); }
60
61
62int main ()
63{
64 int result = 0;
65
66 if (0 != foo<char>())
67 result = result << 1 + 1;
68
69 if (1 != foo<int>())
70 result = result << 1 + 1;
71
72 if (2 != foo<long>())
73 result = result << 1 + 1;
74
75 X x;
76
77 if (0 != bar<char>(x))
78 result = result << 1 + 1;
79
80 if (1 != bar<A<int> >(x).i_)
81 result = result << 1 + 1;
82
83 if (2 != bar<B<long> >(x).i_)
84 result = result << 1 + 1;
85
86 return result;
87}
#define i
Definition 17.names.cpp:126
#define T
Definition 17.names.cpp:163
#define i_
Definition 17.names.cpp:180
#define x
Definition 17.names.cpp:140
volatile int result
int main()
#define foo(buf, s,...)
A(int i)
B(int i)