os/ossrv/ossrv_pub/boost_apis/boost/static_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
//  (C) Copyright John Maddock 2000.
sl@0
     2
//  Use, modification and distribution are subject to the 
sl@0
     3
//  Boost Software License, Version 1.0. (See accompanying file 
sl@0
     4
//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
sl@0
     5
sl@0
     6
//  See http://www.boost.org/libs/static_assert for documentation.
sl@0
     7
sl@0
     8
/*
sl@0
     9
 Revision history:
sl@0
    10
   02 August 2000
sl@0
    11
      Initial version.
sl@0
    12
*/
sl@0
    13
sl@0
    14
#ifndef BOOST_STATIC_ASSERT_HPP
sl@0
    15
#define BOOST_STATIC_ASSERT_HPP
sl@0
    16
sl@0
    17
#include <boost/config.hpp>
sl@0
    18
#include <boost/detail/workaround.hpp>
sl@0
    19
sl@0
    20
#ifdef __BORLANDC__
sl@0
    21
//
sl@0
    22
// workaround for buggy integral-constant expression support:
sl@0
    23
#define BOOST_BUGGY_INTEGRAL_CONSTANT_EXPRESSIONS
sl@0
    24
#endif
sl@0
    25
sl@0
    26
#if defined(__GNUC__) && (__GNUC__ == 3) && ((__GNUC_MINOR__ == 3) || (__GNUC_MINOR__ == 4))
sl@0
    27
// gcc 3.3 and 3.4 don't produce good error messages with the default version:
sl@0
    28
#  define BOOST_SA_GCC_WORKAROUND
sl@0
    29
#endif
sl@0
    30
sl@0
    31
namespace boost{
sl@0
    32
sl@0
    33
// HP aCC cannot deal with missing names for template value parameters
sl@0
    34
template <bool x> struct STATIC_ASSERTION_FAILURE;
sl@0
    35
sl@0
    36
template <> struct STATIC_ASSERTION_FAILURE<true> { enum { value = 1 }; };
sl@0
    37
sl@0
    38
// HP aCC cannot deal with missing names for template value parameters
sl@0
    39
template<int x> struct static_assert_test{};
sl@0
    40
sl@0
    41
}
sl@0
    42
sl@0
    43
//
sl@0
    44
// Implicit instantiation requires that all member declarations be
sl@0
    45
// instantiated, but that the definitions are *not* instantiated.
sl@0
    46
//
sl@0
    47
// It's not particularly clear how this applies to enum's or typedefs;
sl@0
    48
// both are described as declarations [7.1.3] and [7.2] in the standard,
sl@0
    49
// however some compilers use "delayed evaluation" of one or more of
sl@0
    50
// these when implicitly instantiating templates.  We use typedef declarations
sl@0
    51
// by default, but try defining BOOST_USE_ENUM_STATIC_ASSERT if the enum
sl@0
    52
// version gets better results from your compiler...
sl@0
    53
//
sl@0
    54
// Implementation:
sl@0
    55
// Both of these versions rely on sizeof(incomplete_type) generating an error
sl@0
    56
// message containing the name of the incomplete type.  We use
sl@0
    57
// "STATIC_ASSERTION_FAILURE" as the type name here to generate
sl@0
    58
// an eye catching error message.  The result of the sizeof expression is either
sl@0
    59
// used as an enum initialiser, or as a template argument depending which version
sl@0
    60
// is in use...
sl@0
    61
// Note that the argument to the assert is explicitly cast to bool using old-
sl@0
    62
// style casts: too many compilers currently have problems with static_cast
sl@0
    63
// when used inside integral constant expressions.
sl@0
    64
//
sl@0
    65
#if !defined(BOOST_BUGGY_INTEGRAL_CONSTANT_EXPRESSIONS)
sl@0
    66
sl@0
    67
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
sl@0
    68
// __LINE__ macro broken when -ZI is used see Q199057
sl@0
    69
// fortunately MSVC ignores duplicate typedef's.
sl@0
    70
#define BOOST_STATIC_ASSERT( B ) \
sl@0
    71
   typedef ::boost::static_assert_test<\
sl@0
    72
      sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >)\
sl@0
    73
      > boost_static_assert_typedef_
sl@0
    74
#elif defined(BOOST_MSVC)
sl@0
    75
#define BOOST_STATIC_ASSERT( B ) \
sl@0
    76
   typedef ::boost::static_assert_test<\
sl@0
    77
      sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >)>\
sl@0
    78
         BOOST_JOIN(boost_static_assert_typedef_, __COUNTER__)
sl@0
    79
#elif defined(BOOST_INTEL_CXX_VERSION) || defined(BOOST_SA_GCC_WORKAROUND)
sl@0
    80
// agurt 15/sep/02: a special care is needed to force Intel C++ issue an error 
sl@0
    81
// instead of warning in case of failure
sl@0
    82
# define BOOST_STATIC_ASSERT( B ) \
sl@0
    83
    typedef char BOOST_JOIN(boost_static_assert_typedef_, __LINE__) \
sl@0
    84
        [ ::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >::value ]
sl@0
    85
#elif defined(__sgi)
sl@0
    86
// special version for SGI MIPSpro compiler
sl@0
    87
#define BOOST_STATIC_ASSERT( B ) \
sl@0
    88
   BOOST_STATIC_CONSTANT(bool, \
sl@0
    89
     BOOST_JOIN(boost_static_assert_test_, __LINE__) = ( B )); \
sl@0
    90
   typedef ::boost::static_assert_test<\
sl@0
    91
     sizeof(::boost::STATIC_ASSERTION_FAILURE< \
sl@0
    92
       BOOST_JOIN(boost_static_assert_test_, __LINE__) >)>\
sl@0
    93
         BOOST_JOIN(boost_static_assert_typedef_, __LINE__)
sl@0
    94
#elif BOOST_WORKAROUND(__MWERKS__, <= 0x3003)
sl@0
    95
// special version for CodeWarrior <= 8.x
sl@0
    96
#define BOOST_STATIC_ASSERT( B ) \
sl@0
    97
   BOOST_STATIC_CONSTANT(int, \
sl@0
    98
     BOOST_JOIN(boost_static_assert_test_, __LINE__) = \
sl@0
    99
       sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >) )
sl@0
   100
#else
sl@0
   101
// generic version
sl@0
   102
#define BOOST_STATIC_ASSERT( B ) \
sl@0
   103
   typedef ::boost::static_assert_test<\
sl@0
   104
      sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >)>\
sl@0
   105
         BOOST_JOIN(boost_static_assert_typedef_, __LINE__)
sl@0
   106
#endif
sl@0
   107
sl@0
   108
#else
sl@0
   109
// alternative enum based implementation:
sl@0
   110
#define BOOST_STATIC_ASSERT( B ) \
sl@0
   111
   enum { BOOST_JOIN(boost_static_assert_enum_, __LINE__) \
sl@0
   112
      = sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >) }
sl@0
   113
#endif
sl@0
   114
sl@0
   115
sl@0
   116
#endif // BOOST_STATIC_ASSERT_HPP
sl@0
   117
sl@0
   118