]> git.lyx.org Git - lyx.git/blob - boost/boost/static_assert.hpp
major boost update
[lyx.git] / boost / boost / static_assert.hpp
1 //  (C) Copyright John Maddock 2000.
2 //  Permission to copy, use, modify, sell and
3 //  distribute this software is granted provided this copyright notice appears
4 //  in all copies. This software is provided "as is" without express or implied
5 //  warranty, and with no claim as to its suitability for any purpose.
6
7 //  See http://www.boost.org for most recent version including documentation.
8
9 /*
10  Revision history:
11    02 August 2000
12       Initial version.
13 */
14
15 #ifndef BOOST_STATIC_ASSERT_HPP
16 #define BOOST_STATIC_ASSERT_HPP
17
18 #include <boost/config.hpp>
19
20 #ifdef __BORLANDC__
21 //
22 // workaround for buggy integral-constant expression support:
23 #define BOOST_BUGGY_INTEGRAL_CONSTANT_EXPRESSIONS
24 #endif
25
26 namespace boost{
27
28 // HP aCC cannot deal with missing names for template value parameters
29 template <bool x> struct STATIC_ASSERTION_FAILURE;
30
31 template <> struct STATIC_ASSERTION_FAILURE<true>{};
32
33 // HP aCC cannot deal with missing names for template value parameters
34 template<int x> struct static_assert_test{};
35
36 }
37
38 //
39 // Implicit instantiation requires that all member declarations be
40 // instantiated, but that the definitions are *not* instantiated.
41 //
42 // It's not particularly clear how this applies to enum's or typedefs;
43 // both are described as declarations [7.1.3] and [7.2] in the standard,
44 // however some compilers use "delayed evaluation" of one or more of
45 // these when implicitly instantiating templates.  We use typedef declarations
46 // by default, but try defining BOOST_USE_ENUM_STATIC_ASSERT if the enum
47 // version gets better results from your compiler...
48 //
49 // Implementation:
50 // Both of these versions rely on sizeof(incomplete_type) generating an error
51 // message containing the name of the incomplete type.  We use
52 // "STATIC_ASSERTION_FAILURE" as the type name here to generate
53 // an eye catching error message.  The result of the sizeof expression is either
54 // used as an enum initialiser, or as a template argument depending which version
55 // is in use...
56 // Note that the argument to the assert is explicitly cast to bool using old-
57 // style casts: too many compilers currently have problems with static_cast
58 // when used inside integral constant expressions.
59 //
60 #if !defined(BOOST_BUGGY_INTEGRAL_CONSTANT_EXPRESSIONS) && !defined(__MWERKS__)
61 #ifndef BOOST_MSVC
62 #define BOOST_STATIC_ASSERT( B ) \
63    typedef ::boost::static_assert_test<\
64       sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >)>\
65          BOOST_JOIN(boost_static_assert_typedef_, __LINE__)
66 #else
67 // __LINE__ macro broken when -ZI is used see Q199057
68 // fortunately MSVC ignores duplicate typedef's.
69 #define BOOST_STATIC_ASSERT( B ) \
70    typedef ::boost::static_assert_test<\
71       sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >)\
72       > boost_static_assert_typedef_
73 #endif
74 #else
75 // alternative enum based implementation:
76 #define BOOST_STATIC_ASSERT( B ) \
77    enum { BOOST_JOIN(boost_static_assert_enum_, __LINE__) \
78       = sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >) }
79 #endif
80
81
82 #endif // BOOST_STATIC_ASSERT_HPP
83
84
85
86