4 * This program checks if the compiler / platform supports partial
5 * template specialization. The motivation for this test was a
6 * discussion on the development mailing list, and the documentation
9 * http://bugzilla.dre.vanderbilt.edu/show_bug.cgi?id=3715
12 #include "test_config.h"
14 // We are going to test if partial template specializations work by
15 // demonstrating a standard technique in generic programming, i.e.,
16 // using the specialization to detect if a type is a pointer.
18 // My implementation here is not very elegant, I would even say
19 // ackward, and should not be taken as representative of good generic
20 // programming techniques. I just wanted to through something
24 // First some helper types in the anonymous namespace
28 // Now a generic function to convert the types to booleans, moving
29 // from generic type-based programming to classical value-based
32 bool to_boolean(T
const&);
35 bool to_boolean(true_type
const &)
41 bool to_boolean(false_type
const &)
46 // Here is the template, by default return false for all types.
47 // Notice that this is a type *function*, it takes a type and returns
50 struct is_pointer_function
55 // Here is the specialization, for a class of types it results
56 // something different. Effectively this is an implicit if() test on
59 struct is_pointer_function
<T
*>
64 // And here is a helper to convert back to values...
68 static bool is_pointer()
70 is_pointer_function
<T
> v
;
71 return to_boolean(v
.result
);
76 run_main (int, ACE_TCHAR
*[])
78 ACE_START_TEST (ACE_TEXT("Compiler_Features_14_Test"));
80 // As usual, the exit status from the test is 0 on success, 1 on
84 if (test::is_pointer
<int>())
88 ACE_TEXT("int should not be a pointer\n")));
91 if (! test::is_pointer
<int*>())
95 ACE_TEXT("int* should be a pointer\n")));
98 if (test::is_pointer
<int&>())
102 ACE_TEXT("int& should not be a pointer\n")));