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