source: NonGTP/Boost/boost/type_traits/is_reference.hpp @ 857

Revision 857, 4.4 KB checked in by igarcia, 18 years ago (diff)
Line 
1
2//  (C) Copyright Dave Abrahams, Steve Cleary, Beman Dawes,
3//      Howard Hinnant and John Maddock 2000.
4//  (C) Copyright Mat Marcus, Jesse Jones and Adobe Systems Inc 2001
5
6//  Use, modification and distribution are subject to the Boost Software License,
7//  Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8//  http://www.boost.org/LICENSE_1_0.txt).
9//
10//  See http://www.boost.org/libs/type_traits for most recent version including documentation.
11
12//    Fixed is_pointer, is_reference, is_const, is_volatile, is_same,
13//    is_member_pointer based on the Simulated Partial Specialization work
14//    of Mat Marcus and Jesse Jones. See  http://opensource.adobe.com or
15//    http://groups.yahoo.com/group/boost/message/5441
16//    Some workarounds in here use ideas suggested from "Generic<Programming>:
17//    Mappings between Types and Values"
18//    by Andrei Alexandrescu (see http://www.cuj.com/experts/1810/alexandr.html).
19
20
21#ifndef BOOST_TT_IS_REFERENCE_HPP_INCLUDED
22#define BOOST_TT_IS_REFERENCE_HPP_INCLUDED
23
24#include "boost/type_traits/config.hpp"
25
26#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
27#   include "boost/type_traits/detail/yes_no_type.hpp"
28#   include "boost/type_traits/detail/wrap.hpp"
29#endif
30
31// should be the last #include
32#include "boost/type_traits/detail/bool_trait_def.hpp"
33
34namespace boost {
35
36#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
37
38BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_reference,T,false)
39BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_reference,T&,true)
40
41#if defined(__BORLANDC__) && !defined(__COMO__) && (__BORLANDC__ < 0x600)
42// these are illegal specialisations; cv-qualifies applied to
43// references have no effect according to [8.3.2p1],
44// C++ Builder requires them though as it treats cv-qualified
45// references as distinct types...
46BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_reference,T& const,true)
47BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_reference,T& volatile,true)
48BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_reference,T& const volatile,true)
49#endif
50
51#if defined(__GNUC__) && (__GNUC__ < 3)
52// these allow us to work around illegally cv-qualified reference
53// types.
54BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_reference,T const ,::boost::is_reference<T>::value)
55BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_reference,T volatile ,::boost::is_reference<T>::value)
56BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_reference,T const volatile ,::boost::is_reference<T>::value)
57// However, the above specializations confuse gcc 2.96 unless we also
58// supply these specializations for array types
59BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_2(typename T,unsigned long N,is_reference,T[N],false)
60BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_2(typename T,unsigned long N,is_reference,const T[N],false)
61BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_2(typename T,unsigned long N,is_reference,volatile T[N],false)
62BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_2(typename T,unsigned long N,is_reference,const volatile T[N],false)
63#endif
64
65#else
66
67#ifdef BOOST_MSVC
68#   pragma warning(push)
69#   pragma warning(disable: 4181)
70#endif
71
72namespace detail {
73
74using ::boost::type_traits::yes_type;
75using ::boost::type_traits::no_type;
76using ::boost::type_traits::wrap;
77
78template <class T> T&(* is_reference_helper1(wrap<T>) )(wrap<T>);
79char is_reference_helper1(...);
80
81template <class T> no_type is_reference_helper2(T&(*)(wrap<T>));
82yes_type is_reference_helper2(...);
83
84template <typename T>
85struct is_reference_impl
86{
87    BOOST_STATIC_CONSTANT(
88        bool, value = sizeof(
89            ::boost::detail::is_reference_helper2(
90                ::boost::detail::is_reference_helper1(::boost::type_traits::wrap<T>()))) == 1
91        );
92};
93
94BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_reference,void,false)
95#ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
96BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_reference,void const,false)
97BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_reference,void volatile,false)
98BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_reference,void const volatile,false)
99#endif
100
101} // namespace detail
102
103BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_reference,T,::boost::detail::is_reference_impl<T>::value)
104
105#ifdef BOOST_MSVC
106#   pragma warning(pop)
107#endif
108
109#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
110
111} // namespace boost
112
113#include "boost/type_traits/detail/bool_trait_undef.hpp"
114
115#endif // BOOST_TT_IS_REFERENCE_HPP_INCLUDED
116
Note: See TracBrowser for help on using the repository browser.