os/ossrv/ossrv_pub/boost_apis/boost/mpl/assert.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
sl@0
     2
#ifndef BOOST_MPL_ASSERT_HPP_INCLUDED
sl@0
     3
#define BOOST_MPL_ASSERT_HPP_INCLUDED
sl@0
     4
sl@0
     5
// Copyright Aleksey Gurtovoy 2000-2006
sl@0
     6
//
sl@0
     7
// Distributed under the Boost Software License, Version 1.0. 
sl@0
     8
// (See accompanying file LICENSE_1_0.txt or copy at 
sl@0
     9
// http://www.boost.org/LICENSE_1_0.txt)
sl@0
    10
//
sl@0
    11
// See http://www.boost.org/libs/mpl for documentation.
sl@0
    12
sl@0
    13
// $Source: /cvsroot/boost/boost/boost/mpl/assert.hpp,v $
sl@0
    14
// $Date: 2006/11/10 21:31:19 $
sl@0
    15
// $Revision: 1.13.14.6 $
sl@0
    16
sl@0
    17
#include <boost/mpl/not.hpp>
sl@0
    18
#include <boost/mpl/aux_/value_wknd.hpp>
sl@0
    19
#include <boost/mpl/aux_/nested_type_wknd.hpp>
sl@0
    20
#include <boost/mpl/aux_/yes_no.hpp>
sl@0
    21
#include <boost/mpl/aux_/na.hpp>
sl@0
    22
#include <boost/mpl/aux_/adl_barrier.hpp>
sl@0
    23
sl@0
    24
#include <boost/mpl/aux_/config/nttp.hpp>
sl@0
    25
#include <boost/mpl/aux_/config/dtp.hpp>
sl@0
    26
#include <boost/mpl/aux_/config/gcc.hpp>
sl@0
    27
#include <boost/mpl/aux_/config/msvc.hpp>
sl@0
    28
#include <boost/mpl/aux_/config/static_constant.hpp>
sl@0
    29
#include <boost/mpl/aux_/config/workaround.hpp>
sl@0
    30
sl@0
    31
#include <boost/preprocessor/cat.hpp>
sl@0
    32
sl@0
    33
#include <boost/config.hpp> // make sure 'size_t' is placed into 'std'
sl@0
    34
#include <cstddef>
sl@0
    35
sl@0
    36
sl@0
    37
#if BOOST_WORKAROUND(__BORLANDC__, >= 0x560) && BOOST_WORKAROUND(__BORLANDC__, < 0x600) \
sl@0
    38
    || (BOOST_MPL_CFG_GCC != 0) \
sl@0
    39
    || BOOST_WORKAROUND(__IBMCPP__, <= 600)
sl@0
    40
#   define BOOST_MPL_CFG_ASSERT_USE_RELATION_NAMES
sl@0
    41
#endif
sl@0
    42
sl@0
    43
#if BOOST_WORKAROUND(__MWERKS__, < 0x3202) \
sl@0
    44
    || BOOST_WORKAROUND(__EDG_VERSION__, <= 238) \
sl@0
    45
    || BOOST_WORKAROUND(__BORLANDC__, < 0x600) \
sl@0
    46
    || BOOST_WORKAROUND(__DMC__, BOOST_TESTED_AT(0x840))
sl@0
    47
#   define BOOST_MPL_CFG_ASSERT_BROKEN_POINTER_TO_POINTER_TO_MEMBER
sl@0
    48
#endif
sl@0
    49
sl@0
    50
// agurt, 10/nov/06: use enums for Borland (which cannot cope with static constants) 
sl@0
    51
// and GCC (which issues "unused variable" warnings when static constants are used 
sl@0
    52
// at a function scope)
sl@0
    53
#if BOOST_WORKAROUND(__BORLANDC__, < 0x600) \
sl@0
    54
    || (BOOST_MPL_CFG_GCC != 0)
sl@0
    55
#   define BOOST_MPL_AUX_ASSERT_CONSTANT(T, expr) enum { expr }
sl@0
    56
#else
sl@0
    57
#   define BOOST_MPL_AUX_ASSERT_CONSTANT(T, expr) BOOST_STATIC_CONSTANT(T, expr)
sl@0
    58
#endif
sl@0
    59
sl@0
    60
sl@0
    61
BOOST_MPL_AUX_ADL_BARRIER_NAMESPACE_OPEN
sl@0
    62
sl@0
    63
struct failed {};
sl@0
    64
sl@0
    65
// agurt, 24/aug/04: MSVC 7.1 workaround here and below: return/accept 
sl@0
    66
// 'assert<false>' by reference; can't apply it unconditionally -- apparently it
sl@0
    67
// degrades the quality of GCC diagnostics
sl@0
    68
#if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
sl@0
    69
#   define AUX778076_ASSERT_ARG(x) x&
sl@0
    70
#else
sl@0
    71
#   define AUX778076_ASSERT_ARG(x) x
sl@0
    72
#endif
sl@0
    73
sl@0
    74
template< bool C >  struct assert        { typedef void* type; };
sl@0
    75
template<>          struct assert<false> { typedef AUX778076_ASSERT_ARG(assert) type; };
sl@0
    76
sl@0
    77
template< bool C >
sl@0
    78
int assertion_failed( typename assert<C>::type );
sl@0
    79
sl@0
    80
template< bool C >
sl@0
    81
struct assertion
sl@0
    82
{
sl@0
    83
    static int failed( assert<false> );
sl@0
    84
};
sl@0
    85
sl@0
    86
template<>
sl@0
    87
struct assertion<true>
sl@0
    88
{
sl@0
    89
    static int failed( void* );
sl@0
    90
};
sl@0
    91
sl@0
    92
struct assert_
sl@0
    93
{
sl@0
    94
#if !defined(BOOST_MPL_CFG_NO_DEFAULT_PARAMETERS_IN_NESTED_TEMPLATES)
sl@0
    95
    template< typename T1, typename T2 = na, typename T3 = na, typename T4 = na > struct types {};
sl@0
    96
#endif
sl@0
    97
    static assert_ const arg;
sl@0
    98
    enum relations { equal = 1, not_equal, greater, greater_equal, less, less_equal };
sl@0
    99
};
sl@0
   100
sl@0
   101
sl@0
   102
#if !defined(BOOST_MPL_CFG_ASSERT_USE_RELATION_NAMES)
sl@0
   103
sl@0
   104
bool operator==( failed, failed );
sl@0
   105
bool operator!=( failed, failed );
sl@0
   106
bool operator>( failed, failed );
sl@0
   107
bool operator>=( failed, failed );
sl@0
   108
bool operator<( failed, failed );
sl@0
   109
bool operator<=( failed, failed );
sl@0
   110
sl@0
   111
#if defined(__EDG_VERSION__)
sl@0
   112
template< bool (*)(failed, failed), long x, long y > struct assert_relation {};
sl@0
   113
#   define BOOST_MPL_AUX_ASSERT_RELATION(x, y, r) assert_relation<r,x,y>
sl@0
   114
#else
sl@0
   115
template< BOOST_MPL_AUX_NTTP_DECL(long, x), BOOST_MPL_AUX_NTTP_DECL(long, y), bool (*)(failed, failed) > 
sl@0
   116
struct assert_relation {};
sl@0
   117
#   define BOOST_MPL_AUX_ASSERT_RELATION(x, y, r) assert_relation<x,y,r>
sl@0
   118
#endif
sl@0
   119
sl@0
   120
#else // BOOST_MPL_CFG_ASSERT_USE_RELATION_NAMES
sl@0
   121
sl@0
   122
boost::mpl::aux::weighted_tag<1>::type operator==( assert_, assert_ );
sl@0
   123
boost::mpl::aux::weighted_tag<2>::type operator!=( assert_, assert_ );
sl@0
   124
boost::mpl::aux::weighted_tag<3>::type operator>(  assert_, assert_ );
sl@0
   125
boost::mpl::aux::weighted_tag<4>::type operator>=( assert_, assert_ );
sl@0
   126
boost::mpl::aux::weighted_tag<5>::type operator<( assert_, assert_ );
sl@0
   127
boost::mpl::aux::weighted_tag<6>::type operator<=( assert_, assert_ );
sl@0
   128
sl@0
   129
template< assert_::relations r, long x, long y > struct assert_relation {};
sl@0
   130
sl@0
   131
#endif 
sl@0
   132
sl@0
   133
sl@0
   134
#if !defined(BOOST_MPL_CFG_ASSERT_BROKEN_POINTER_TO_POINTER_TO_MEMBER)
sl@0
   135
sl@0
   136
template< bool > struct assert_arg_pred_impl { typedef int type; };
sl@0
   137
template<> struct assert_arg_pred_impl<true> { typedef void* type; };
sl@0
   138
sl@0
   139
template< typename P > struct assert_arg_pred
sl@0
   140
{
sl@0
   141
    typedef typename P::type p_type;
sl@0
   142
    typedef typename assert_arg_pred_impl< p_type::value >::type type;
sl@0
   143
};
sl@0
   144
sl@0
   145
template< typename P > struct assert_arg_pred_not
sl@0
   146
{
sl@0
   147
    typedef typename P::type p_type;
sl@0
   148
    BOOST_MPL_AUX_ASSERT_CONSTANT( bool, p = !p_type::value );
sl@0
   149
    typedef typename assert_arg_pred_impl<p>::type type;
sl@0
   150
};
sl@0
   151
sl@0
   152
template< typename Pred >
sl@0
   153
failed ************ (Pred::************ 
sl@0
   154
      assert_arg( void (*)(Pred), typename assert_arg_pred<Pred>::type )
sl@0
   155
    );
sl@0
   156
sl@0
   157
template< typename Pred >
sl@0
   158
failed ************ (boost::mpl::not_<Pred>::************ 
sl@0
   159
      assert_not_arg( void (*)(Pred), typename assert_arg_pred_not<Pred>::type )
sl@0
   160
    );
sl@0
   161
sl@0
   162
template< typename Pred >
sl@0
   163
AUX778076_ASSERT_ARG(assert<false>)
sl@0
   164
assert_arg( void (*)(Pred), typename assert_arg_pred_not<Pred>::type );
sl@0
   165
sl@0
   166
template< typename Pred >
sl@0
   167
AUX778076_ASSERT_ARG(assert<false>)
sl@0
   168
assert_not_arg( void (*)(Pred), typename assert_arg_pred<Pred>::type );
sl@0
   169
sl@0
   170
sl@0
   171
#else // BOOST_MPL_CFG_ASSERT_BROKEN_POINTER_TO_POINTER_TO_MEMBER
sl@0
   172
        
sl@0
   173
template< bool c, typename Pred > struct assert_arg_type_impl
sl@0
   174
{
sl@0
   175
    typedef failed      ************ Pred::* mwcw83_wknd;
sl@0
   176
    typedef mwcw83_wknd ************* type;
sl@0
   177
};
sl@0
   178
sl@0
   179
template< typename Pred > struct assert_arg_type_impl<true,Pred>
sl@0
   180
{
sl@0
   181
    typedef AUX778076_ASSERT_ARG(assert<false>) type;
sl@0
   182
};
sl@0
   183
sl@0
   184
template< typename Pred > struct assert_arg_type
sl@0
   185
    : assert_arg_type_impl< BOOST_MPL_AUX_VALUE_WKND(BOOST_MPL_AUX_NESTED_TYPE_WKND(Pred))::value, Pred >
sl@0
   186
{
sl@0
   187
};
sl@0
   188
sl@0
   189
template< typename Pred >
sl@0
   190
typename assert_arg_type<Pred>::type 
sl@0
   191
assert_arg(void (*)(Pred), int);
sl@0
   192
sl@0
   193
template< typename Pred >
sl@0
   194
typename assert_arg_type< boost::mpl::not_<Pred> >::type 
sl@0
   195
assert_not_arg(void (*)(Pred), int);
sl@0
   196
sl@0
   197
#   if !defined(BOOST_MPL_CFG_ASSERT_USE_RELATION_NAMES)
sl@0
   198
template< long x, long y, bool (*r)(failed, failed) >
sl@0
   199
typename assert_arg_type_impl< false,BOOST_MPL_AUX_ASSERT_RELATION(x,y,r) >::type
sl@0
   200
assert_rel_arg( BOOST_MPL_AUX_ASSERT_RELATION(x,y,r) );
sl@0
   201
#   else
sl@0
   202
template< assert_::relations r, long x, long y >
sl@0
   203
typename assert_arg_type_impl< false,assert_relation<r,x,y> >::type
sl@0
   204
assert_rel_arg( assert_relation<r,x,y> );
sl@0
   205
#   endif
sl@0
   206
sl@0
   207
#endif // BOOST_MPL_CFG_ASSERT_BROKEN_POINTER_TO_POINTER_TO_MEMBER
sl@0
   208
sl@0
   209
#undef AUX778076_ASSERT_ARG
sl@0
   210
sl@0
   211
BOOST_MPL_AUX_ADL_BARRIER_NAMESPACE_CLOSE
sl@0
   212
sl@0
   213
sl@0
   214
// BOOST_MPL_ASSERT((pred<x,...>))
sl@0
   215
sl@0
   216
#define BOOST_MPL_ASSERT(pred) \
sl@0
   217
BOOST_MPL_AUX_ASSERT_CONSTANT( \
sl@0
   218
      std::size_t \
sl@0
   219
    , BOOST_PP_CAT(mpl_assertion_in_line_,__LINE__) = sizeof( \
sl@0
   220
          boost::mpl::assertion_failed<false>( \
sl@0
   221
              boost::mpl::assert_arg( (void (*) pred)0, 1 ) \
sl@0
   222
            ) \
sl@0
   223
        ) \
sl@0
   224
    ) \
sl@0
   225
/**/
sl@0
   226
sl@0
   227
// BOOST_MPL_ASSERT_NOT((pred<x,...>))
sl@0
   228
sl@0
   229
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
sl@0
   230
#   define BOOST_MPL_ASSERT_NOT(pred) \
sl@0
   231
enum { \
sl@0
   232
    BOOST_PP_CAT(mpl_assertion_in_line_,__LINE__) = sizeof( \
sl@0
   233
          boost::mpl::assertion<false>::failed( \
sl@0
   234
              boost::mpl::assert_not_arg( (void (*) pred)0, 1 ) \
sl@0
   235
            ) \
sl@0
   236
        ) \
sl@0
   237
}\
sl@0
   238
/**/
sl@0
   239
#else
sl@0
   240
#   define BOOST_MPL_ASSERT_NOT(pred) \
sl@0
   241
BOOST_MPL_AUX_ASSERT_CONSTANT( \
sl@0
   242
      std::size_t \
sl@0
   243
    , BOOST_PP_CAT(mpl_assertion_in_line_,__LINE__) = sizeof( \
sl@0
   244
          boost::mpl::assertion_failed<false>( \
sl@0
   245
              boost::mpl::assert_not_arg( (void (*) pred)0, 1 ) \
sl@0
   246
            ) \
sl@0
   247
        ) \
sl@0
   248
   ) \
sl@0
   249
/**/
sl@0
   250
#endif
sl@0
   251
sl@0
   252
// BOOST_MPL_ASSERT_RELATION(x, ==|!=|<=|<|>=|>, y)
sl@0
   253
sl@0
   254
#if defined(BOOST_MPL_CFG_ASSERT_USE_RELATION_NAMES)
sl@0
   255
sl@0
   256
#   if !defined(BOOST_MPL_CFG_ASSERT_BROKEN_POINTER_TO_POINTER_TO_MEMBER)
sl@0
   257
// agurt, 9/nov/06: 'enum' below is a workaround for gcc 4.0.4/4.1.1 bugs #29522 and #29518
sl@0
   258
#   define BOOST_MPL_ASSERT_RELATION(x, rel, y) \
sl@0
   259
enum { BOOST_PP_CAT(mpl_assert_rel_value,__LINE__) = (x rel y) }; \
sl@0
   260
BOOST_MPL_AUX_ASSERT_CONSTANT( \
sl@0
   261
      std::size_t \
sl@0
   262
    , BOOST_PP_CAT(mpl_assertion_in_line_,__LINE__) = sizeof( \
sl@0
   263
        boost::mpl::assertion_failed<BOOST_PP_CAT(mpl_assert_rel_value,__LINE__)>( \
sl@0
   264
            (boost::mpl::failed ************ ( boost::mpl::assert_relation< \
sl@0
   265
                  boost::mpl::assert_::relations( sizeof( \
sl@0
   266
                      boost::mpl::assert_::arg rel boost::mpl::assert_::arg \
sl@0
   267
                    ) ) \
sl@0
   268
                , x \
sl@0
   269
                , y \
sl@0
   270
                >::************)) 0 ) \
sl@0
   271
        ) \
sl@0
   272
    ) \
sl@0
   273
/**/
sl@0
   274
#   else
sl@0
   275
#   define BOOST_MPL_ASSERT_RELATION(x, rel, y) \
sl@0
   276
BOOST_MPL_AUX_ASSERT_CONSTANT( \
sl@0
   277
      std::size_t \
sl@0
   278
    , BOOST_PP_CAT(mpl_assert_rel,__LINE__) = sizeof( \
sl@0
   279
          boost::mpl::assert_::arg rel boost::mpl::assert_::arg \
sl@0
   280
        ) \
sl@0
   281
    ); \
sl@0
   282
BOOST_MPL_AUX_ASSERT_CONSTANT( bool, BOOST_PP_CAT(mpl_assert_rel_value,__LINE__) = (x rel y) ); \
sl@0
   283
BOOST_MPL_AUX_ASSERT_CONSTANT( \
sl@0
   284
      std::size_t \
sl@0
   285
    , BOOST_PP_CAT(mpl_assertion_in_line_,__LINE__) = sizeof( \
sl@0
   286
        boost::mpl::assertion_failed<BOOST_PP_CAT(mpl_assert_rel_value,__LINE__)>( \
sl@0
   287
              boost::mpl::assert_rel_arg( boost::mpl::assert_relation< \
sl@0
   288
                  boost::mpl::assert_::relations(BOOST_PP_CAT(mpl_assert_rel,__LINE__)) \
sl@0
   289
                , x \
sl@0
   290
                , y \
sl@0
   291
                >() ) \
sl@0
   292
            ) \
sl@0
   293
        ) \
sl@0
   294
    ) \
sl@0
   295
/**/
sl@0
   296
#   endif
sl@0
   297
sl@0
   298
#else // !BOOST_MPL_CFG_ASSERT_USE_RELATION_NAMES
sl@0
   299
sl@0
   300
#   if defined(BOOST_MPL_CFG_ASSERT_BROKEN_POINTER_TO_POINTER_TO_MEMBER)
sl@0
   301
#   define BOOST_MPL_ASSERT_RELATION(x, rel, y) \
sl@0
   302
BOOST_MPL_AUX_ASSERT_CONSTANT( \
sl@0
   303
      std::size_t \
sl@0
   304
    , BOOST_PP_CAT(mpl_assertion_in_line_,__LINE__) = sizeof( \
sl@0
   305
        boost::mpl::assertion_failed<(x rel y)>( boost::mpl::assert_rel_arg( \
sl@0
   306
              boost::mpl::BOOST_MPL_AUX_ASSERT_RELATION(x,y,(&boost::mpl::operator rel))() \
sl@0
   307
            ) ) \
sl@0
   308
        ) \
sl@0
   309
    ) \
sl@0
   310
/**/
sl@0
   311
#   else
sl@0
   312
#   define BOOST_MPL_ASSERT_RELATION(x, rel, y) \
sl@0
   313
BOOST_MPL_AUX_ASSERT_CONSTANT( \
sl@0
   314
      std::size_t \
sl@0
   315
    , BOOST_PP_CAT(mpl_assertion_in_line_,__LINE__) = sizeof( \
sl@0
   316
        boost::mpl::assertion_failed<(x rel y)>( (boost::mpl::failed ************ ( \
sl@0
   317
            boost::mpl::BOOST_MPL_AUX_ASSERT_RELATION(x,y,(&boost::mpl::operator rel))::************))0 ) \
sl@0
   318
        ) \
sl@0
   319
    ) \
sl@0
   320
/**/
sl@0
   321
#   endif
sl@0
   322
sl@0
   323
#endif
sl@0
   324
sl@0
   325
sl@0
   326
// BOOST_MPL_ASSERT_MSG( (pred<x,...>::value), USER_PROVIDED_MESSAGE, (types<x,...>) ) 
sl@0
   327
sl@0
   328
#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3202))
sl@0
   329
#   define BOOST_MPL_ASSERT_MSG( c, msg, types_ ) \
sl@0
   330
struct msg; \
sl@0
   331
typedef struct BOOST_PP_CAT(msg,__LINE__) : boost::mpl::assert_ \
sl@0
   332
{ \
sl@0
   333
    using boost::mpl::assert_::types; \
sl@0
   334
    static boost::mpl::failed ************ (msg::************ assert_arg()) types_ \
sl@0
   335
    { return 0; } \
sl@0
   336
} BOOST_PP_CAT(mpl_assert_arg,__LINE__); \
sl@0
   337
BOOST_MPL_AUX_ASSERT_CONSTANT( \
sl@0
   338
      std::size_t \
sl@0
   339
    , BOOST_PP_CAT(mpl_assertion_in_line_,__LINE__) = sizeof( \
sl@0
   340
        boost::mpl::assertion<(c)>::failed( BOOST_PP_CAT(mpl_assert_arg,__LINE__)::assert_arg() ) \
sl@0
   341
        ) \
sl@0
   342
    ) \
sl@0
   343
/**/
sl@0
   344
#else
sl@0
   345
#   define BOOST_MPL_ASSERT_MSG( c, msg, types_ ) \
sl@0
   346
struct msg; \
sl@0
   347
typedef struct BOOST_PP_CAT(msg,__LINE__) : boost::mpl::assert_ \
sl@0
   348
{ \
sl@0
   349
    static boost::mpl::failed ************ (msg::************ assert_arg()) types_ \
sl@0
   350
    { return 0; } \
sl@0
   351
} BOOST_PP_CAT(mpl_assert_arg,__LINE__); \
sl@0
   352
BOOST_MPL_AUX_ASSERT_CONSTANT( \
sl@0
   353
      std::size_t \
sl@0
   354
    , BOOST_PP_CAT(mpl_assertion_in_line_,__LINE__) = sizeof( \
sl@0
   355
        boost::mpl::assertion_failed<(c)>( BOOST_PP_CAT(mpl_assert_arg,__LINE__)::assert_arg() ) \
sl@0
   356
        ) \
sl@0
   357
    ) \
sl@0
   358
/**/
sl@0
   359
#endif
sl@0
   360
sl@0
   361
#endif // BOOST_MPL_ASSERT_HPP_INCLUDED