]> git.lyx.org Git - lyx.git/blob - boost/boost/detail/indirect_traits.hpp
update to boost 1.32.0
[lyx.git] / boost / boost / detail / indirect_traits.hpp
1 // Copyright David Abrahams 2002.
2 // Distributed under the Boost Software License, Version 1.0. (See
3 // accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 #ifndef INDIRECT_TRAITS_DWA2002131_HPP
6 # define INDIRECT_TRAITS_DWA2002131_HPP
7 # include <boost/type_traits/is_function.hpp>
8 # include <boost/type_traits/is_reference.hpp>
9 # include <boost/type_traits/is_pointer.hpp>
10 # include <boost/type_traits/is_class.hpp>
11 # include <boost/type_traits/is_const.hpp>
12 # include <boost/type_traits/is_volatile.hpp>
13 # include <boost/type_traits/is_member_function_pointer.hpp>
14 # include <boost/type_traits/remove_cv.hpp>
15 # include <boost/type_traits/remove_reference.hpp>
16 # include <boost/type_traits/remove_pointer.hpp>
17
18 # include <boost/type_traits/detail/ice_and.hpp>
19 # include <boost/detail/workaround.hpp>
20
21 # include <boost/mpl/if.hpp>
22 # include <boost/mpl/bool.hpp>
23 # include <boost/mpl/and.hpp>
24 # include <boost/mpl/not.hpp>
25 # include <boost/mpl/aux_/lambda_support.hpp>
26
27 #  ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
28 #   include <boost/detail/is_function_ref_tester.hpp>
29 #  endif 
30
31 namespace boost { namespace detail {
32
33 namespace indirect_traits {
34
35 #  ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
36 template <class T>
37 struct is_reference_to_const : mpl::false_
38 {
39 };
40
41 template <class T>
42 struct is_reference_to_const<T const&> : mpl::true_
43 {
44 };
45
46 #   if defined(BOOST_MSVC) && _MSC_FULL_VER <= 13102140 // vc7.01 alpha workaround
47 template<class T>
48 struct is_reference_to_const<T const volatile&> : mpl::true_
49 {
50 };
51 #   endif 
52
53 template <class T>
54 struct is_reference_to_function : mpl::false_
55 {
56 };
57
58 template <class T>
59 struct is_reference_to_function<T&> : is_function<T>
60 {
61 };
62
63 template <class T>
64 struct is_pointer_to_function : mpl::false_
65 {
66 };
67
68 // There's no such thing as a pointer-to-cv-function, so we don't need
69 // specializations for those
70 template <class T>
71 struct is_pointer_to_function<T*> : is_function<T>
72 {
73 };
74
75 template <class T>
76 struct is_reference_to_member_function_pointer_impl : mpl::false_
77 {
78 };
79
80 template <class T>
81 struct is_reference_to_member_function_pointer_impl<T&>
82     : is_member_function_pointer<typename remove_cv<T>::type>
83 {
84 };
85
86
87 template <class T>
88 struct is_reference_to_member_function_pointer
89     : is_reference_to_member_function_pointer_impl<T>
90 {
91     BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_member_function_pointer,(T))
92 };
93
94 template <class T>
95 struct is_reference_to_function_pointer_aux
96     : mpl::and_<
97           is_reference<T>
98         , is_pointer_to_function<
99               typename remove_cv<
100                   typename remove_reference<T>::type
101               >::type
102           >
103       >
104 {
105     // There's no such thing as a pointer-to-cv-function, so we don't need specializations for those
106 };
107
108 template <class T>
109 struct is_reference_to_function_pointer
110     : mpl::if_<
111           is_reference_to_function<T>
112         , mpl::false_
113         , is_reference_to_function_pointer_aux<T>
114      >::type
115 {
116 };
117
118 template <class T>
119 struct is_reference_to_non_const
120     : mpl::and_<
121           is_reference<T>
122         , mpl::not_<
123              is_reference_to_const<T>
124           >
125       >
126 {
127 };
128
129 template <class T>
130 struct is_reference_to_volatile : mpl::false_
131 {
132 };
133
134 template <class T>
135 struct is_reference_to_volatile<T volatile&> : mpl::true_
136 {
137 };
138
139 #   if defined(BOOST_MSVC) && _MSC_FULL_VER <= 13102140 // vc7.01 alpha workaround
140 template <class T>
141 struct is_reference_to_volatile<T const volatile&> : mpl::true_
142 {
143 };
144 #   endif 
145
146
147 template <class T>
148 struct is_reference_to_pointer : mpl::false_
149 {
150 };
151
152 template <class T>
153 struct is_reference_to_pointer<T*&> : mpl::true_
154 {
155 };
156
157 template <class T>
158 struct is_reference_to_pointer<T* const&> : mpl::true_
159 {
160 };
161
162 template <class T>
163 struct is_reference_to_pointer<T* volatile&> : mpl::true_
164 {
165 };
166
167 template <class T>
168 struct is_reference_to_pointer<T* const volatile&> : mpl::true_
169 {
170 };
171
172 template <class T>
173 struct is_reference_to_class
174     : mpl::and_<
175           is_reference<T>
176         , is_class<
177               typename remove_cv<
178                   typename remove_reference<T>::type
179               >::type
180           >
181       >
182 {
183     BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_class,(T))
184 };
185
186 template <class T>
187 struct is_pointer_to_class
188     : mpl::and_<
189           is_pointer<T>
190         , is_class<
191               typename remove_cv<
192                   typename remove_pointer<T>::type
193               >::type
194           >
195       >
196 {
197     BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_pointer_to_class,(T))
198 };
199
200 #  else
201
202 using namespace boost::detail::is_function_ref_tester_;
203
204 typedef char (&inner_yes_type)[3];
205 typedef char (&inner_no_type)[2];
206 typedef char (&outer_no_type)[1];
207
208 template <typename V>
209 struct is_const_help
210 {
211     typedef typename mpl::if_<
212           is_const<V>
213         , inner_yes_type
214         , inner_no_type
215         >::type type;
216 };
217
218 template <typename V>
219 struct is_volatile_help
220 {
221     typedef typename mpl::if_<
222           is_volatile<V>
223         , inner_yes_type
224         , inner_no_type
225         >::type type;
226 };
227
228 template <typename V>
229 struct is_pointer_help
230 {
231     typedef typename mpl::if_<
232           is_pointer<V>
233         , inner_yes_type
234         , inner_no_type
235         >::type type;
236 };
237
238 template <typename V>
239 struct is_class_help
240 {
241     typedef typename mpl::if_<
242           is_class<V>
243         , inner_yes_type
244         , inner_no_type
245         >::type type;
246 };
247
248 template <class T>
249 struct is_reference_to_function_aux
250 {
251     static T t;
252     BOOST_STATIC_CONSTANT(
253         bool, value = sizeof(detail::is_function_ref_tester(t,0)) == sizeof(::boost::type_traits::yes_type));
254  };
255
256 template <class T>
257 struct is_reference_to_function
258     : mpl::if_<is_reference<T>, is_reference_to_function_aux<T>, mpl::bool_<false> >::type
259 {
260 };
261
262 template <class T>
263 struct is_pointer_to_function_aux
264 {
265     static T t;
266     BOOST_STATIC_CONSTANT(
267         bool, value
268         = sizeof(::boost::type_traits::is_function_ptr_tester(t)) == sizeof(::boost::type_traits::yes_type));
269     typedef mpl::bool_<value> type;
270 };
271
272 template <class T>
273 struct is_pointer_to_function
274     : mpl::if_<is_pointer<T>, is_pointer_to_function_aux<T>, mpl::bool_<false> >::type
275 {
276     BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_pointer_to_function,(T))
277 };
278
279 struct false_helper1
280 {
281     template <class T>
282     struct apply : mpl::false_
283     {
284     };
285 };
286
287 template <typename V>
288 typename is_const_help<V>::type reference_to_const_helper(V&);    
289 outer_no_type
290 reference_to_const_helper(...);
291
292 struct true_helper1
293 {
294     template <class T>
295     struct apply
296     {
297         static T t;
298         BOOST_STATIC_CONSTANT(
299             bool, value
300             = sizeof(reference_to_const_helper(t)) == sizeof(inner_yes_type));
301         typedef mpl::bool_<value> type;
302     };
303 };
304
305 template <bool ref = true>
306 struct is_reference_to_const_helper1 : true_helper1
307 {
308 };
309
310 template <>
311 struct is_reference_to_const_helper1<false> : false_helper1
312 {
313 };
314
315
316 template <class T>
317 struct is_reference_to_const
318     : is_reference_to_const_helper1<is_reference<T>::value>::template apply<T>
319 {
320 };
321
322
323 template <bool ref = true>
324 struct is_reference_to_non_const_helper1
325 {
326     template <class T>
327     struct apply
328     {
329         static T t;
330         BOOST_STATIC_CONSTANT(
331             bool, value
332             = sizeof(reference_to_const_helper(t)) == sizeof(inner_no_type));
333     };
334 };
335
336 template <>
337 struct is_reference_to_non_const_helper1<false> : false_helper1
338 {
339 };
340
341
342 template <class T>
343 struct is_reference_to_non_const
344     : is_reference_to_non_const_helper1<is_reference<T>::value>::template apply<T>
345 {
346 };
347
348
349 template <typename V>
350 typename is_volatile_help<V>::type reference_to_volatile_helper(V&);    
351 outer_no_type
352 reference_to_volatile_helper(...);
353
354 template <bool ref = true>
355 struct is_reference_to_volatile_helper1
356 {
357     template <class T>
358     struct apply
359     {
360         static T t;
361         BOOST_STATIC_CONSTANT(
362             bool, value
363             = sizeof(reference_to_volatile_helper(t)) == sizeof(inner_yes_type));
364     };
365 };
366
367 template <>
368 struct is_reference_to_volatile_helper1<false> : false_helper1
369 {
370 };
371
372
373 template <class T>
374 struct is_reference_to_volatile
375     : is_reference_to_volatile_helper1<is_reference<T>::value>::template apply<T>
376 {
377 };
378
379 template <typename V>
380 typename is_pointer_help<V>::type reference_to_pointer_helper(V&);
381 outer_no_type reference_to_pointer_helper(...);
382
383 template <class T>
384 struct is_reference_to_pointer
385 {
386     static T t;
387     BOOST_STATIC_CONSTANT(
388         bool, value
389         = (is_reference<T>::value
390            && sizeof((reference_to_pointer_helper)(t)) == sizeof(inner_yes_type))
391         );
392 };
393
394 template <class T>
395 struct is_reference_to_function_pointer
396     : mpl::if_<
397         is_reference<T>
398         , is_pointer_to_function_aux<T>
399         , mpl::bool_<false>
400      >::type
401 {
402     BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_function_pointer,(T))
403 };
404
405
406 template <class T>
407 struct is_member_function_pointer_help
408     : mpl::if_<is_member_function_pointer<T>, inner_yes_type, inner_no_type>
409 {};
410
411 template <typename V>
412 typename is_member_function_pointer_help<V>::type member_function_pointer_helper(V&);
413 outer_no_type member_function_pointer_helper(...);
414
415 template <class T>
416 struct is_pointer_to_member_function_aux
417 {
418     static T t;
419     BOOST_STATIC_CONSTANT(
420         bool, value
421         = sizeof((member_function_pointer_helper)(t)) == sizeof(inner_yes_type));
422     typedef mpl::bool_<value> type;
423 };
424
425 template <class T>
426 struct is_reference_to_member_function_pointer
427     : mpl::if_<
428         is_reference<T>
429         , is_pointer_to_member_function_aux<T>
430         , mpl::bool_<false>
431      >::type
432 {
433     BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_member_function_pointer,(T))
434 };
435
436 template <typename V>
437 typename is_class_help<V>::type reference_to_class_helper(V const volatile&);
438 outer_no_type reference_to_class_helper(...);
439
440 template <class T>
441 struct is_reference_to_class
442 {
443     static T t;
444     BOOST_STATIC_CONSTANT(
445         bool, value
446         = (is_reference<T>::value
447            & (sizeof(reference_to_class_helper(t)) == sizeof(inner_yes_type)))
448         );
449     typedef mpl::bool_<value> type;
450     BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_reference_to_class,(T))
451 };
452
453 template <typename V>
454 typename is_class_help<V>::type pointer_to_class_helper(V const volatile*);
455 outer_no_type pointer_to_class_helper(...);
456
457 template <class T>
458 struct is_pointer_to_class
459 {
460     static T t;
461     BOOST_STATIC_CONSTANT(
462         bool, value
463         = (is_pointer<T>::value
464            && sizeof(pointer_to_class_helper(t)) == sizeof(inner_yes_type))
465         );
466 };
467 #  endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION 
468
469 }
470
471 using namespace indirect_traits;
472
473 }} // namespace boost::python::detail
474
475 #endif // INDIRECT_TRAITS_DWA2002131_HPP