os/ossrv/ossrv_pub/boost_apis/boost/mpl/has_xxx.hpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
sl@0
     2
#ifndef BOOST_MPL_HAS_XXX_HPP_INCLUDED
sl@0
     3
#define BOOST_MPL_HAS_XXX_HPP_INCLUDED
sl@0
     4
sl@0
     5
// Copyright Aleksey Gurtovoy 2002-2006
sl@0
     6
// Copyright David Abrahams 2002-2003
sl@0
     7
//
sl@0
     8
// Distributed under the Boost Software License, Version 1.0. 
sl@0
     9
// (See accompanying file LICENSE_1_0.txt or copy at 
sl@0
    10
// http://www.boost.org/LICENSE_1_0.txt)
sl@0
    11
//
sl@0
    12
// See http://www.boost.org/libs/mpl for documentation.
sl@0
    13
sl@0
    14
// $Source: /cvsroot/boost/boost/boost/mpl/has_xxx.hpp,v $
sl@0
    15
// $Date: 2006/11/09 01:05:31 $
sl@0
    16
// $Revision: 1.4.6.1 $
sl@0
    17
sl@0
    18
#include <boost/mpl/bool.hpp>
sl@0
    19
#include <boost/mpl/aux_/type_wrapper.hpp>
sl@0
    20
#include <boost/mpl/aux_/yes_no.hpp>
sl@0
    21
#include <boost/mpl/aux_/config/has_xxx.hpp>
sl@0
    22
#include <boost/mpl/aux_/config/msvc_typename.hpp>
sl@0
    23
#include <boost/mpl/aux_/config/msvc.hpp>
sl@0
    24
#include <boost/mpl/aux_/config/static_constant.hpp>
sl@0
    25
#include <boost/mpl/aux_/config/workaround.hpp>
sl@0
    26
sl@0
    27
#include <boost/preprocessor/cat.hpp>
sl@0
    28
sl@0
    29
#if !defined(BOOST_MPL_CFG_NO_HAS_XXX)
sl@0
    30
sl@0
    31
#   if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
sl@0
    32
sl@0
    33
// agurt, 11/sep/02: MSVC-specific version (< 7.1), based on a USENET 
sl@0
    34
// newsgroup's posting by John Madsen (comp.lang.c++.moderated, 
sl@0
    35
// 1999-11-12 19:17:06 GMT); the code is _not_ standard-conforming, but 
sl@0
    36
// it works way more reliably than the SFINAE-based implementation
sl@0
    37
sl@0
    38
// Modified dwa 8/Oct/02 to handle reference types.
sl@0
    39
sl@0
    40
#   include <boost/mpl/if.hpp>
sl@0
    41
#   include <boost/mpl/bool.hpp>
sl@0
    42
sl@0
    43
namespace boost { namespace mpl { namespace aux {
sl@0
    44
sl@0
    45
struct has_xxx_tag;
sl@0
    46
sl@0
    47
#if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
sl@0
    48
template< typename U > struct msvc_incomplete_array
sl@0
    49
{
sl@0
    50
    typedef char (&type)[sizeof(U) + 1];
sl@0
    51
};
sl@0
    52
#endif
sl@0
    53
sl@0
    54
template< typename T >
sl@0
    55
struct msvc_is_incomplete
sl@0
    56
{
sl@0
    57
    // MSVC is capable of some kinds of SFINAE.  If U is an incomplete
sl@0
    58
    // type, it won't pick the second overload
sl@0
    59
    static char tester(...);
sl@0
    60
sl@0
    61
#if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
sl@0
    62
    template< typename U >
sl@0
    63
    static typename msvc_incomplete_array<U>::type tester(type_wrapper<U>);
sl@0
    64
#else
sl@0
    65
    template< typename U >
sl@0
    66
    static char (& tester(type_wrapper<U>) )[sizeof(U)+1];
sl@0
    67
#endif 
sl@0
    68
    
sl@0
    69
    BOOST_STATIC_CONSTANT(bool, value = 
sl@0
    70
          sizeof(tester(type_wrapper<T>())) == 1
sl@0
    71
        );
sl@0
    72
};
sl@0
    73
sl@0
    74
template<>
sl@0
    75
struct msvc_is_incomplete<int>
sl@0
    76
{
sl@0
    77
    BOOST_STATIC_CONSTANT(bool, value = false);
sl@0
    78
};
sl@0
    79
sl@0
    80
}}}
sl@0
    81
sl@0
    82
#   define BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF_(trait, name, default_) \
sl@0
    83
template< typename T, typename name = ::boost::mpl::aux::has_xxx_tag > \
sl@0
    84
struct BOOST_PP_CAT(trait,_impl) : T \
sl@0
    85
{ \
sl@0
    86
    static boost::mpl::aux::no_tag \
sl@0
    87
    test(void(*)(::boost::mpl::aux::has_xxx_tag)); \
sl@0
    88
    \
sl@0
    89
    static boost::mpl::aux::yes_tag test(...); \
sl@0
    90
    \
sl@0
    91
    BOOST_STATIC_CONSTANT(bool, value = \
sl@0
    92
          sizeof(test(static_cast<void(*)(name)>(0))) \
sl@0
    93
            != sizeof(boost::mpl::aux::no_tag) \
sl@0
    94
        ); \
sl@0
    95
    typedef boost::mpl::bool_<value> type; \
sl@0
    96
}; \
sl@0
    97
\
sl@0
    98
template< typename T, typename fallback_ = boost::mpl::bool_<default_> > \
sl@0
    99
struct trait \
sl@0
   100
    : boost::mpl::if_c< \
sl@0
   101
          boost::mpl::aux::msvc_is_incomplete<T>::value \
sl@0
   102
        , boost::mpl::bool_<false> \
sl@0
   103
        , BOOST_PP_CAT(trait,_impl)<T> \
sl@0
   104
        >::type \
sl@0
   105
{ \
sl@0
   106
}; \
sl@0
   107
\
sl@0
   108
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, void) \
sl@0
   109
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, bool) \
sl@0
   110
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, char) \
sl@0
   111
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, signed char) \
sl@0
   112
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, unsigned char) \
sl@0
   113
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, signed short) \
sl@0
   114
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, unsigned short) \
sl@0
   115
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, signed int) \
sl@0
   116
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, unsigned int) \
sl@0
   117
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, signed long) \
sl@0
   118
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, unsigned long) \
sl@0
   119
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, float) \
sl@0
   120
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, double) \
sl@0
   121
BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, long double) \
sl@0
   122
/**/
sl@0
   123
sl@0
   124
#   define BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, T) \
sl@0
   125
template<> struct trait<T> \
sl@0
   126
{ \
sl@0
   127
    BOOST_STATIC_CONSTANT(bool, value = false); \
sl@0
   128
    typedef boost::mpl::bool_<false> type; \
sl@0
   129
}; \
sl@0
   130
/**/
sl@0
   131
sl@0
   132
#if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
sl@0
   133
#   define BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, unused) \
sl@0
   134
    BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF_(trait, name, unused) \
sl@0
   135
    BOOST_MPL_AUX_HAS_XXX_TRAIT_SPEC(trait, wchar_t) \
sl@0
   136
/**/
sl@0
   137
#else
sl@0
   138
#   define BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, unused) \
sl@0
   139
    BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF_(trait, name, unused) \
sl@0
   140
/**/
sl@0
   141
#endif
sl@0
   142
sl@0
   143
sl@0
   144
// SFINAE-based implementations below are derived from a USENET newsgroup's 
sl@0
   145
// posting by Rani Sharoni (comp.lang.c++.moderated, 2002-03-17 07:45:09 PST)
sl@0
   146
sl@0
   147
#   elif BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1400)) \
sl@0
   148
      || BOOST_WORKAROUND(__IBMCPP__, <= 700)
sl@0
   149
sl@0
   150
// MSVC 7.1+ & VACPP
sl@0
   151
sl@0
   152
// agurt, 15/jun/05: replace overload-based SFINAE implementation with SFINAE
sl@0
   153
// applied to partial specialization to fix some apparently random failures 
sl@0
   154
// (thanks to Daniel Wallin for researching this!)
sl@0
   155
sl@0
   156
namespace boost { namespace mpl { namespace aux {
sl@0
   157
template< typename T > struct msvc71_sfinae_helper { typedef void type; };
sl@0
   158
}}}
sl@0
   159
sl@0
   160
#   define BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, default_) \
sl@0
   161
template< typename T, typename U = void > \
sl@0
   162
struct BOOST_PP_CAT(trait,_impl_) \
sl@0
   163
{ \
sl@0
   164
    BOOST_STATIC_CONSTANT(bool, value = false); \
sl@0
   165
    typedef boost::mpl::bool_<value> type; \
sl@0
   166
}; \
sl@0
   167
\
sl@0
   168
template< typename T > \
sl@0
   169
struct BOOST_PP_CAT(trait,_impl_)< \
sl@0
   170
      T \
sl@0
   171
    , typename boost::mpl::aux::msvc71_sfinae_helper< typename T::name >::type \
sl@0
   172
    > \
sl@0
   173
{ \
sl@0
   174
    BOOST_STATIC_CONSTANT(bool, value = true); \
sl@0
   175
    typedef boost::mpl::bool_<value> type; \
sl@0
   176
}; \
sl@0
   177
\
sl@0
   178
template< typename T, typename fallback_ = boost::mpl::bool_<default_> > \
sl@0
   179
struct trait \
sl@0
   180
    : BOOST_PP_CAT(trait,_impl_)<T> \
sl@0
   181
{ \
sl@0
   182
}; \
sl@0
   183
/**/
sl@0
   184
sl@0
   185
#   else // other SFINAE-capable compilers
sl@0
   186
sl@0
   187
#   define BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, default_) \
sl@0
   188
template< typename T, typename fallback_ = boost::mpl::bool_<default_> > \
sl@0
   189
struct trait \
sl@0
   190
{ \
sl@0
   191
    struct gcc_3_2_wknd \
sl@0
   192
    { \
sl@0
   193
        template< typename U > \
sl@0
   194
        static boost::mpl::aux::yes_tag test( \
sl@0
   195
              boost::mpl::aux::type_wrapper<U> const volatile* \
sl@0
   196
            , boost::mpl::aux::type_wrapper<BOOST_MSVC_TYPENAME U::name>* = 0 \
sl@0
   197
            ); \
sl@0
   198
    \
sl@0
   199
        static boost::mpl::aux::no_tag test(...); \
sl@0
   200
    }; \
sl@0
   201
    \
sl@0
   202
    typedef boost::mpl::aux::type_wrapper<T> t_; \
sl@0
   203
    BOOST_STATIC_CONSTANT(bool, value = \
sl@0
   204
          sizeof(gcc_3_2_wknd::test(static_cast<t_*>(0))) \
sl@0
   205
            == sizeof(boost::mpl::aux::yes_tag) \
sl@0
   206
        ); \
sl@0
   207
    typedef boost::mpl::bool_<value> type; \
sl@0
   208
}; \
sl@0
   209
/**/
sl@0
   210
sl@0
   211
#   endif // BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
sl@0
   212
sl@0
   213
sl@0
   214
#else // BOOST_MPL_CFG_NO_HAS_XXX
sl@0
   215
sl@0
   216
// placeholder implementation
sl@0
   217
sl@0
   218
#   define BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(trait, name, default_) \
sl@0
   219
template< typename T, typename fallback_ = boost::mpl::bool_<default_> > \
sl@0
   220
struct trait \
sl@0
   221
{ \
sl@0
   222
    BOOST_STATIC_CONSTANT(bool, value = fallback_::value); \
sl@0
   223
    typedef fallback_ type; \
sl@0
   224
}; \
sl@0
   225
/**/
sl@0
   226
sl@0
   227
#endif
sl@0
   228
sl@0
   229
#define BOOST_MPL_HAS_XXX_TRAIT_DEF(name) \
sl@0
   230
    BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(BOOST_PP_CAT(has_,name), name, false) \
sl@0
   231
/**/
sl@0
   232
sl@0
   233
#endif // BOOST_MPL_HAS_XXX_HPP_INCLUDED