~ubuntu-branches/ubuntu/warty/aqsis/warty

« back to all changes in this revision

Viewing changes to boost/boost/mpl/aux_/has_xxx.hpp

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-08-24 07:25:04 UTC
  • Revision ID: james.westby@ubuntu.com-20040824072504-zf993vnevvisdsvb
Tags: upstream-0.9.1
ImportĀ upstreamĀ versionĀ 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//-----------------------------------------------------------------------------
 
2
// boost mpl/aux_/has_xxx.hpp header file
 
3
// See http://www.boost.org for updates, documentation, and revision history.
 
4
//-----------------------------------------------------------------------------
 
5
//
 
6
// Copyright (c) 2002
 
7
// Aleksey Gurtovoy
 
8
//
 
9
// Permission to use, copy, modify, distribute and sell this software
 
10
// and its documentation for any purpose is hereby granted without fee, 
 
11
// provided that the above copyright notice appears in all copies and 
 
12
// that both the copyright notice and this permission notice appear in 
 
13
// supporting documentation. No representations are made about the 
 
14
// suitability of this software for any purpose. It is provided "as is" 
 
15
// without express or implied warranty.
 
16
 
 
17
#ifndef BOOST_MPL_AUX_HAS_XXX_HPP_INCLUDED
 
18
#define BOOST_MPL_AUX_HAS_XXX_HPP_INCLUDED
 
19
 
 
20
#include "boost/mpl/aux_/type_wrapper.hpp"
 
21
#include "boost/mpl/aux_/yes_no.hpp"
 
22
#include "boost/mpl/aux_/config/msvc_typename.hpp"
 
23
#include "boost/mpl/aux_/config/overload_resolution.hpp"
 
24
#include "boost/mpl/aux_/config/static_constant.hpp"
 
25
 
 
26
#if !defined(BOOST_MPL_BROKEN_OVERLOAD_RESOLUTION) && (!defined(__GNUC__) || __GNUC__ == 3)
 
27
 
 
28
#   if (!defined(BOOST_MSVC) || BOOST_MSVC > 1300)
 
29
 
 
30
// the implementation below is based on a USENET newsgroup's posting by  
 
31
// Rani Sharoni (comp.lang.c++.moderated, 2002-03-17 07:45:09 PST)
 
32
 
 
33
#   define BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, unused) \
 
34
template< typename T > \
 
35
boost::mpl::aux::yes_tag \
 
36
trait##_helper( \
 
37
      boost::mpl::aux::type_wrapper<T> const volatile* \
 
38
    , boost::mpl::aux::type_wrapper<BOOST_MSVC_TYPENAME T::name>* = 0 \
 
39
    ); \
 
40
\
 
41
boost::mpl::aux::no_tag \
 
42
trait##_helper(...); \
 
43
\
 
44
template< typename T > \
 
45
struct trait \
 
46
{ \
 
47
    typedef boost::mpl::aux::type_wrapper<T> t_; \
 
48
    BOOST_STATIC_CONSTANT(bool, value = \
 
49
          sizeof((trait##_helper)(static_cast<t_*>(0))) \
 
50
            == sizeof(boost::mpl::aux::yes_tag) \
 
51
        ); \
 
52
}; \
 
53
/**/
 
54
 
 
55
#   else
 
56
 
 
57
#include "boost/mpl/if.hpp"
 
58
#include "boost/mpl/bool.hpp"
 
59
#include "boost/preprocessor/cat.hpp"
 
60
 
 
61
// agurt, 11/sep/02: MSVC version, based on a USENET newsgroup's posting by 
 
62
// John Madsen (comp.lang.c++.moderated, 1999-11-12 19:17:06 GMT);
 
63
// note that the code is _not_ standard-conforming, but it works, 
 
64
// and it resolves some nasty ICE cases with the above implementation
 
65
 
 
66
// Modified dwa 8/Oct/02 to handle reference types.
 
67
 
 
68
namespace boost { namespace mpl { namespace aux {
 
69
 
 
70
struct has_xxx_tag;
 
71
 
 
72
template< typename T >
 
73
struct msvc_is_incomplete
 
74
{
 
75
    struct incomplete_;
 
76
    BOOST_STATIC_CONSTANT(bool, value = 
 
77
          sizeof(void (T::*)()) == sizeof(void (incomplete_::*)())
 
78
        );
 
79
};
 
80
 
 
81
template<>
 
82
struct msvc_is_incomplete<int>
 
83
{
 
84
    BOOST_STATIC_CONSTANT(bool, value = false);
 
85
};
 
86
 
 
87
}}}
 
88
 
 
89
#   define BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF_(trait, name, unused) \
 
90
template< typename T, typename name = ::boost::mpl::aux::has_xxx_tag > \
 
91
struct BOOST_PP_CAT(trait,_impl) : T \
 
92
{ \
 
93
 private: \
 
94
    static boost::mpl::aux::no_tag test(void(*)(::boost::mpl::aux::has_xxx_tag)); \
 
95
    static boost::mpl::aux::yes_tag test(...); \
 
96
\
 
97
 public: \
 
98
    BOOST_STATIC_CONSTANT(bool, value =  \
 
99
        sizeof(test(static_cast<void(*)(name)>(0))) \
 
100
            != sizeof(boost::mpl::aux::no_tag) \
 
101
        ); \
 
102
}; \
 
103
\
 
104
template< typename T > struct trait \
 
105
    : boost::mpl::if_c< \
 
106
          boost::mpl::aux::msvc_is_incomplete<T>::value \
 
107
        , boost::mpl::bool_<false> \
 
108
        , BOOST_PP_CAT(trait,_impl)<T> \
 
109
        >::type \
 
110
{ \
 
111
}; \
 
112
\
 
113
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, void) \
 
114
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, bool) \
 
115
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, char) \
 
116
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, signed char) \
 
117
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, unsigned char) \
 
118
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, signed short) \
 
119
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, unsigned short) \
 
120
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, signed int) \
 
121
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, unsigned int) \
 
122
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, signed long) \
 
123
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, unsigned long) \
 
124
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, float) \
 
125
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, double) \
 
126
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, long double) \
 
127
/**/
 
128
 
 
129
#   define BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, T) \
 
130
template<> struct trait<T> \
 
131
{ \
 
132
    BOOST_STATIC_CONSTANT(bool,value = false); \
 
133
}; \
 
134
/**/
 
135
 
 
136
#if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
 
137
#   define BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, unused) \
 
138
    BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF_(trait, name, unused) \
 
139
    BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, wchar_t) \
 
140
    /**/
 
141
#else
 
142
#   define BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, unused) \
 
143
    BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF_(trait, name, unused) \
 
144
    /**/
 
145
#endif
 
146
 
 
147
#   endif // BOOST_MSVC > 1300
 
148
 
 
149
#else 
 
150
 
 
151
// agurt, 11/jan/03: signals a stub-only implementation
 
152
#   define BOOST_NO_MPL_AUX_HAS_XXX
 
153
 
 
154
#   define BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, default_value) \
 
155
template< typename T > \
 
156
struct trait \
 
157
{ \
 
158
     BOOST_STATIC_CONSTANT(bool, value = default_value); \
 
159
}; \
 
160
/**/
 
161
 
 
162
#endif // BOOST_MPL_BROKEN_OVERLOAD_RESOLUTION
 
163
 
 
164
#define BOOST_MPL_HAS_XXX_TRAIT_DEF(name) \
 
165
BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_##name, name, false) \
 
166
/**/
 
167
 
 
168
#endif // BOOST_MPL_AUX_HAS_XXX_HPP_INCLUDED