]> AND Private Git Repository - canny.git/blob - stc/exp/ml_stc_linux_make_v1.0/include/boost/static_assert.hpp
Logo AND Algorithmique Numérique Distribuée

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