1 
2 // Copyright Aleksey Gurtovoy 2000-2004
3 // Copyright Daniel Walker 2007
4 //
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 //
9 // See http://www.boost.org/libs/mpl for documentation.
10 
11 // $Id$
12 // $Date$
13 // $Revision$
14 
15 #include <boost/mpl/has_xxx.hpp>
16 #include <boost/mpl/aux_/config/workaround.hpp>
17 #include <boost/mpl/aux_/test.hpp>
18 
19 BOOST_MPL_HAS_XXX_TRAIT_DEF(xxx)
20 BOOST_MPL_HAS_XXX_TEMPLATE_NAMED_DEF(has_xxx_template, xxx, false)
21 BOOST_MPL_HAS_XXX_TEMPLATE_DEF(yyy)
22 
23 struct a1 {};
24 struct a2 { void xxx(); };
25 struct a3 { int xxx; };
26 struct a4 { static int xxx(); };
27 struct a5 { template< typename T > struct xxx {}; };
28 
29 struct b1 { typedef int xxx; };
30 struct b2 { struct xxx; };
31 struct b3 { typedef int& xxx; };
32 struct b4 { typedef int* xxx; };
33 struct b5 { typedef int xxx[10]; };
34 struct b6 { typedef void (*xxx)(); };
35 struct b7 { typedef void (xxx)(); };
36 
37 struct c1 { template< typename T > struct xxx {}; };
38 struct c2 { template< typename T1, typename T2 > struct xxx {}; };
39 struct c3 { template< typename T1, typename T2, typename T3 > struct xxx {}; };
40 struct c4 { template< typename T1, typename T2, typename T3, typename T4 > struct xxx {}; };
41 struct c5 { template< typename T1, typename T2, typename T3, typename T4, typename T5 > struct xxx {}; };
42 struct c6 { template< typename T > struct yyy {}; };
43 struct c7 { template< typename T1, typename T2 > struct yyy {}; };
44 
45 template< typename T > struct outer;
46 template< typename T > struct inner { typedef typename T::type type; };
47 
48 // agurt, 15/aug/04: make sure MWCW passes the test in presence of the following
49 // template
50 template< typename T > struct xxx;
51 
52 
MPL_TEST_CASE()53 MPL_TEST_CASE()
54 {
55     MPL_ASSERT_NOT(( has_xxx<int> ));
56     MPL_ASSERT_NOT(( has_xxx_template<int> ));
57 
58 #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
59     MPL_ASSERT_NOT(( has_xxx<int&> ));
60     MPL_ASSERT_NOT(( has_xxx_template<int&> ));
61 
62     MPL_ASSERT_NOT(( has_xxx<int*> ));
63     MPL_ASSERT_NOT(( has_xxx_template<int*> ));
64 
65     MPL_ASSERT_NOT(( has_xxx<int[]> ));
66     MPL_ASSERT_NOT(( has_xxx_template<int[]> ));
67 
68     MPL_ASSERT_NOT(( has_xxx<int (*)()> ));
69     MPL_ASSERT_NOT(( has_xxx_template<int (*)()> ));
70 
71     MPL_ASSERT_NOT(( has_xxx<a2> ));
72     MPL_ASSERT_NOT(( has_xxx_template<a2> ));
73 
74     MPL_ASSERT_NOT(( has_xxx<a3> ));
75     MPL_ASSERT_NOT(( has_xxx_template<a3> ));
76 
77     MPL_ASSERT_NOT(( has_xxx<a4> ));
78     MPL_ASSERT_NOT(( has_xxx_template<a4> ));
79 
80 #if !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3202))
81     MPL_ASSERT_NOT(( has_xxx<a5> ));
82     MPL_ASSERT(( has_xxx_template<a5> ));
83 #endif
84     MPL_ASSERT_NOT(( has_xxx< enum_ > ));
85     MPL_ASSERT_NOT(( has_xxx_template< enum_ > ));
86 #endif
87 
88     MPL_ASSERT_NOT(( has_xxx<a1> ));
89     MPL_ASSERT_NOT(( has_xxx_template<a1> ));
90 
91     MPL_ASSERT_NOT(( has_xxx< outer< inner<int> > > ));
92     MPL_ASSERT_NOT(( has_xxx_template< outer< inner<int> > > ));
93 
94     MPL_ASSERT_NOT(( has_xxx< incomplete > ));
95     MPL_ASSERT_NOT(( has_xxx_template< incomplete > ));
96 
97     MPL_ASSERT_NOT(( has_xxx< abstract > ));
98     MPL_ASSERT_NOT(( has_xxx_template< abstract > ));
99 
100     MPL_ASSERT_NOT(( has_xxx< noncopyable > ));
101     MPL_ASSERT_NOT(( has_xxx_template< noncopyable > ));
102 
103 #if !BOOST_WORKAROUND(__COMO_VERSION__, BOOST_TESTED_AT(4308))
104     MPL_ASSERT_NOT(( has_xxx_template<b1> ));
105     MPL_ASSERT_NOT(( has_xxx_template<b2> ));
106     MPL_ASSERT_NOT(( has_xxx_template<b3> ));
107     MPL_ASSERT_NOT(( has_xxx_template<b4> ));
108     MPL_ASSERT_NOT(( has_xxx_template<b5> ));
109     MPL_ASSERT_NOT(( has_xxx_template<b6> ));
110     MPL_ASSERT_NOT(( has_xxx_template<b7> ));
111 #endif
112 
113     // Same name, different args.
114     MPL_ASSERT(( has_xxx_template<c1> ));
115     MPL_ASSERT(( has_xxx_template<c2> ));
116     MPL_ASSERT(( has_xxx_template<c3> ));
117     MPL_ASSERT(( has_xxx_template<c4> ));
118     MPL_ASSERT(( has_xxx_template<c5> ));
119     MPL_ASSERT(( has_yyy<c6> ));
120     MPL_ASSERT(( has_yyy<c7> ));
121 
122     // Different name, different args.
123     MPL_ASSERT_NOT(( has_xxx_template<c6> ));
124     MPL_ASSERT_NOT(( has_xxx_template<c7> ));
125     MPL_ASSERT_NOT(( has_yyy<c1> ));
126     MPL_ASSERT_NOT(( has_yyy<c2> ));
127     MPL_ASSERT_NOT(( has_yyy<c3> ));
128     MPL_ASSERT_NOT(( has_yyy<c4> ));
129     MPL_ASSERT_NOT(( has_yyy<c5> ));
130 
131     MPL_ASSERT(( has_xxx<b1,true_> ));
132     MPL_ASSERT(( has_xxx<b2,true_> ));
133     MPL_ASSERT(( has_xxx<b3,true_> ));
134     MPL_ASSERT(( has_xxx<b4,true_> ));
135     MPL_ASSERT(( has_xxx<b5,true_> ));
136     MPL_ASSERT(( has_xxx<b6,true_> ));
137     MPL_ASSERT(( has_xxx<b7,true_> ));
138 
139     MPL_ASSERT(( has_xxx_template<c1,true_> ));
140 
141 #if !defined(HAS_XXX_ASSERT)
142 #   define HAS_XXX_ASSERT(x) MPL_ASSERT(x)
143 #endif
144 
145     HAS_XXX_ASSERT(( has_xxx<b1> ));
146     HAS_XXX_ASSERT(( has_xxx<b2> ));
147     HAS_XXX_ASSERT(( has_xxx<b3> ));
148     HAS_XXX_ASSERT(( has_xxx<b4> ));
149     HAS_XXX_ASSERT(( has_xxx<b5> ));
150     HAS_XXX_ASSERT(( has_xxx<b6> ));
151     HAS_XXX_ASSERT(( has_xxx<b7> ));
152 
153 #if !defined(HAS_XXX_TEMPLATE_ASSERT)
154 #   define HAS_XXX_TEMPLATE_ASSERT(x) MPL_ASSERT(x)
155 #endif
156 
157     HAS_XXX_TEMPLATE_ASSERT(( has_xxx_template<c1> ));
158 }
159