mirror of
https://github.com/boostorg/static_assert.git
synced 2025-06-27 21:11:01 +02:00
Compare commits
13 Commits
svn-branch
...
boost-1.37
Author | SHA1 | Date | |
---|---|---|---|
5928da3e36 | |||
3488b2bdf2 | |||
28e09a3cca | |||
481c2efbac | |||
3b702727b9 | |||
f298ed51a9 | |||
851fd2622e | |||
720fb456d5 | |||
2fa11699bf | |||
69dbf6f12d | |||
66dd3d2595 | |||
7a0a3fbf32 | |||
c5de8ff789 |
29
Jamfile
29
Jamfile
@ -1,29 +0,0 @@
|
|||||||
# copyright John Maddock 2003
|
|
||||||
|
|
||||||
subproject libs/static_assert ;
|
|
||||||
# bring in the rules for testing
|
|
||||||
import testing ;
|
|
||||||
|
|
||||||
test-suite static_assert :
|
|
||||||
[ run static_assert_test.cpp ]
|
|
||||||
# [ run static_assert_example_1.cpp ]
|
|
||||||
[ run static_assert_example_2.cpp ]
|
|
||||||
[ run static_assert_example_3.cpp ]
|
|
||||||
[ compile-fail static_assert_test_fail_1.cpp ]
|
|
||||||
[ compile-fail static_assert_test_fail_2.cpp ]
|
|
||||||
[ compile-fail static_assert_test_fail_3.cpp ]
|
|
||||||
[ compile-fail static_assert_test_fail_4.cpp ]
|
|
||||||
[ compile-fail static_assert_test_fail_5.cpp ]
|
|
||||||
[ compile-fail static_assert_test_fail_6.cpp ]
|
|
||||||
[ compile-fail static_assert_test_fail_7.cpp ]
|
|
||||||
[ compile-fail static_assert_test_fail_8.cpp ]
|
|
||||||
[ compile-fail static_assert_test_fail_9.cpp ]
|
|
||||||
[ compile-fail static_assert_test_fail_10.cpp ]
|
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
|||||||
# copyright John Maddock 2003
|
# copyright John Maddock 2003
|
||||||
|
# Use, modification and distribution are subject to the
|
||||||
|
# Boost Software License, Version 1.0. (See accompanying file
|
||||||
|
# LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
# bring in the rules for testing
|
# bring in the rules for testing
|
||||||
import testing ;
|
import testing ;
|
||||||
@ -25,3 +28,4 @@ test-suite static_assert :
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,6 +15,10 @@
|
|||||||
[last-revision $Date$]
|
[last-revision $Date$]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
This manual is also available in
|
||||||
|
[@http://svn.boost.org/svn/boost/sandbox/pdf/static_assert/release/static_assert.pdf
|
||||||
|
printer friendly PDF format].
|
||||||
|
|
||||||
[section:intro Overview and Tutorial]
|
[section:intro Overview and Tutorial]
|
||||||
|
|
||||||
The header `<boost/static_assert.hpp>` supplies a single macro `BOOST_STATIC_ASSERT(x)`,
|
The header `<boost/static_assert.hpp>` supplies a single macro `BOOST_STATIC_ASSERT(x)`,
|
||||||
@ -49,11 +53,12 @@ be an unsigned type. We can verify this at compile time as follows:
|
|||||||
|
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <cwchar>
|
#include <cwchar>
|
||||||
|
#include <limits>
|
||||||
#include <boost/static_assert.hpp>
|
#include <boost/static_assert.hpp>
|
||||||
|
|
||||||
namespace my_conditions {
|
namespace my_conditions {
|
||||||
|
|
||||||
BOOST_STATIC_ASSERT(sizeof(int) * CHAR_BIT >= 32);
|
BOOST_STATIC_ASSERT(std::numeric_limits<int>::digits >= 32);
|
||||||
BOOST_STATIC_ASSERT(WCHAR_MIN >= 0);
|
BOOST_STATIC_ASSERT(WCHAR_MIN >= 0);
|
||||||
|
|
||||||
} // namespace my_conditions
|
} // namespace my_conditions
|
||||||
@ -61,7 +66,7 @@ be an unsigned type. We can verify this at compile time as follows:
|
|||||||
The use of the namespace my_conditions here requires some comment.
|
The use of the namespace my_conditions here requires some comment.
|
||||||
The macro `BOOST_STATIC_ASSERT` works by generating an typedef declaration,
|
The macro `BOOST_STATIC_ASSERT` works by generating an typedef declaration,
|
||||||
and since the typedef must have a name, the macro generates one automatically by
|
and since the typedef must have a name, the macro generates one automatically by
|
||||||
mangling a stub name with the value of __LINE__. When `BOOST_STATIC_ASSERT` is
|
mangling a stub name with the value of `__LINE__`. When `BOOST_STATIC_ASSERT` is
|
||||||
used at either class or function scope then each use of `BOOST_STATIC_ASSERT`
|
used at either class or function scope then each use of `BOOST_STATIC_ASSERT`
|
||||||
is guaranteed to produce a name unique to that scope (provided you only use
|
is guaranteed to produce a name unique to that scope (provided you only use
|
||||||
the macro once on each line). However when used in a header at namespace
|
the macro once on each line). However when used in a header at namespace
|
||||||
@ -93,12 +98,17 @@ the user that the template is being misused.
|
|||||||
#include <boost/type_traits.hpp>
|
#include <boost/type_traits.hpp>
|
||||||
|
|
||||||
template <class RandomAccessIterator >
|
template <class RandomAccessIterator >
|
||||||
RandomAccessIterator foo(RandomAccessIterator from, RandomAccessIterator to)
|
RandomAccessIterator foo(RandomAccessIterator from,
|
||||||
|
RandomAccessIterator to)
|
||||||
{
|
{
|
||||||
// this template can only be used with
|
// this template can only be used with
|
||||||
// random access iterators...
|
// random access iterators...
|
||||||
typedef typename std::iterator_traits< RandomAccessIterator >::iterator_category cat;
|
typedef typename std::iterator_traits<
|
||||||
BOOST_STATIC_ASSERT((boost::is_convertible<cat, const std::random_access_iterator_tag&>::value));
|
RandomAccessIterator >::iterator_category cat;
|
||||||
|
BOOST_STATIC_ASSERT(
|
||||||
|
(boost::is_convertible<
|
||||||
|
cat,
|
||||||
|
const std::random_access_iterator_tag&>::value));
|
||||||
//
|
//
|
||||||
// detail goes here...
|
// detail goes here...
|
||||||
return from;
|
return from;
|
||||||
@ -128,8 +138,8 @@ using something like this:
|
|||||||
class myclass
|
class myclass
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
BOOST_STATIC_ASSERT(sizeof(UnsignedInt) * CHAR_BIT >= 16);
|
BOOST_STATIC_ASSERT((std::numeric_limits<UnsignedInt>::digits >= 16)
|
||||||
BOOST_STATIC_ASSERT(std::numeric_limits<UnsignedInt>::is_specialized
|
&& std::numeric_limits<UnsignedInt>::is_specialized
|
||||||
&& std::numeric_limits<UnsignedInt>::is_integer
|
&& std::numeric_limits<UnsignedInt>::is_integer
|
||||||
&& !std::numeric_limits<UnsignedInt>::is_signed);
|
&& !std::numeric_limits<UnsignedInt>::is_signed);
|
||||||
public:
|
public:
|
||||||
@ -216,3 +226,5 @@ working at namespace, function, and class scope outweighed the ugliness of a mac
|
|||||||
]
|
]
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,6 +28,20 @@
|
|||||||
# define BOOST_SA_GCC_WORKAROUND
|
# define BOOST_SA_GCC_WORKAROUND
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//
|
||||||
|
// If the compiler issues warnings about old C style casts,
|
||||||
|
// then enable this:
|
||||||
|
//
|
||||||
|
#if defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 4)))
|
||||||
|
# define BOOST_STATIC_ASSERT_BOOL_CAST( x ) ((x) == 0 ? false : true)
|
||||||
|
#else
|
||||||
|
# define BOOST_STATIC_ASSERT_BOOL_CAST(x) (bool)(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef BOOST_HAS_STATIC_ASSERT
|
||||||
|
# define BOOST_STATIC_ASSERT( B ) static_assert(B, #B)
|
||||||
|
#else
|
||||||
|
|
||||||
namespace boost{
|
namespace boost{
|
||||||
|
|
||||||
// HP aCC cannot deal with missing names for template value parameters
|
// HP aCC cannot deal with missing names for template value parameters
|
||||||
@ -74,14 +88,14 @@ template<int x> struct static_assert_test{};
|
|||||||
#elif defined(BOOST_MSVC)
|
#elif defined(BOOST_MSVC)
|
||||||
#define BOOST_STATIC_ASSERT( B ) \
|
#define BOOST_STATIC_ASSERT( B ) \
|
||||||
typedef ::boost::static_assert_test<\
|
typedef ::boost::static_assert_test<\
|
||||||
sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >)>\
|
sizeof(::boost::STATIC_ASSERTION_FAILURE< BOOST_STATIC_ASSERT_BOOL_CAST ( B ) >)>\
|
||||||
BOOST_JOIN(boost_static_assert_typedef_, __COUNTER__)
|
BOOST_JOIN(boost_static_assert_typedef_, __COUNTER__)
|
||||||
#elif defined(BOOST_INTEL_CXX_VERSION) || defined(BOOST_SA_GCC_WORKAROUND)
|
#elif defined(BOOST_INTEL_CXX_VERSION) || defined(BOOST_SA_GCC_WORKAROUND)
|
||||||
// agurt 15/sep/02: a special care is needed to force Intel C++ issue an error
|
// agurt 15/sep/02: a special care is needed to force Intel C++ issue an error
|
||||||
// instead of warning in case of failure
|
// instead of warning in case of failure
|
||||||
# define BOOST_STATIC_ASSERT( B ) \
|
# define BOOST_STATIC_ASSERT( B ) \
|
||||||
typedef char BOOST_JOIN(boost_static_assert_typedef_, __LINE__) \
|
typedef char BOOST_JOIN(boost_static_assert_typedef_, __LINE__) \
|
||||||
[ ::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >::value ]
|
[ ::boost::STATIC_ASSERTION_FAILURE< BOOST_STATIC_ASSERT_BOOL_CAST( B ) >::value ]
|
||||||
#elif defined(__sgi)
|
#elif defined(__sgi)
|
||||||
// special version for SGI MIPSpro compiler
|
// special version for SGI MIPSpro compiler
|
||||||
#define BOOST_STATIC_ASSERT( B ) \
|
#define BOOST_STATIC_ASSERT( B ) \
|
||||||
@ -96,12 +110,12 @@ template<int x> struct static_assert_test{};
|
|||||||
#define BOOST_STATIC_ASSERT( B ) \
|
#define BOOST_STATIC_ASSERT( B ) \
|
||||||
BOOST_STATIC_CONSTANT(int, \
|
BOOST_STATIC_CONSTANT(int, \
|
||||||
BOOST_JOIN(boost_static_assert_test_, __LINE__) = \
|
BOOST_JOIN(boost_static_assert_test_, __LINE__) = \
|
||||||
sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >) )
|
sizeof(::boost::STATIC_ASSERTION_FAILURE< BOOST_STATIC_ASSERT_BOOL_CAST( B ) >) )
|
||||||
#else
|
#else
|
||||||
// generic version
|
// generic version
|
||||||
#define BOOST_STATIC_ASSERT( B ) \
|
#define BOOST_STATIC_ASSERT( B ) \
|
||||||
typedef ::boost::static_assert_test<\
|
typedef ::boost::static_assert_test<\
|
||||||
sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >)>\
|
sizeof(::boost::STATIC_ASSERTION_FAILURE< BOOST_STATIC_ASSERT_BOOL_CAST( B ) >)>\
|
||||||
BOOST_JOIN(boost_static_assert_typedef_, __LINE__)
|
BOOST_JOIN(boost_static_assert_typedef_, __LINE__)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -111,7 +125,7 @@ template<int x> struct static_assert_test{};
|
|||||||
enum { BOOST_JOIN(boost_static_assert_enum_, __LINE__) \
|
enum { BOOST_JOIN(boost_static_assert_enum_, __LINE__) \
|
||||||
= sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >) }
|
= sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >) }
|
||||||
#endif
|
#endif
|
||||||
|
#endif // ndef BOOST_HAS_STATIC_ASSERT
|
||||||
|
|
||||||
#endif // BOOST_STATIC_ASSERT_HPP
|
#endif // BOOST_STATIC_ASSERT_HPP
|
||||||
|
|
||||||
|
@ -9,6 +9,10 @@
|
|||||||
or view the online version at
|
or view the online version at
|
||||||
<a href="http://www.boost.org/regression-logs/cs-win32_metacomm/doc/html/boost_staticassert.html">
|
<a href="http://www.boost.org/regression-logs/cs-win32_metacomm/doc/html/boost_staticassert.html">
|
||||||
http://www.boost.org/regression-logs/cs-win32_metacomm/doc/html/boost_staticassert.html</a>
|
http://www.boost.org/regression-logs/cs-win32_metacomm/doc/html/boost_staticassert.html</a>
|
||||||
|
<P>Copyright John Maddock 2006</P>
|
||||||
|
<P>Distributed under the Boost Software License, Version 1.0. (See accompanying file <A href="../../LICENSE_1_0.txt">
|
||||||
|
LICENSE_1_0.txt</A> or copy at <A href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</A>).</P>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,6 +9,10 @@
|
|||||||
or view the online version at
|
or view the online version at
|
||||||
<a href="http://www.boost.org/regression-logs/cs-win32_metacomm/doc/html/boost_staticassert.html">
|
<a href="http://www.boost.org/regression-logs/cs-win32_metacomm/doc/html/boost_staticassert.html">
|
||||||
http://www.boost.org/regression-logs/cs-win32_metacomm/doc/html/boost_staticassert.html</a>
|
http://www.boost.org/regression-logs/cs-win32_metacomm/doc/html/boost_staticassert.html</a>
|
||||||
|
<P>Copyright John Maddock 2006</P>
|
||||||
|
<P>Distributed under the Boost Software License, Version 1.0. (See accompanying file <A href="../../LICENSE_1_0.txt">
|
||||||
|
LICENSE_1_0.txt</A> or copy at <A href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</A>).</P>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <cwchar>
|
#include <cwchar>
|
||||||
|
#include <limits>
|
||||||
#include <boost/static_assert.hpp>
|
#include <boost/static_assert.hpp>
|
||||||
|
|
||||||
#if !defined(WCHAR_MIN)
|
#if !defined(WCHAR_MIN)
|
||||||
@ -16,7 +17,7 @@
|
|||||||
namespace boost{
|
namespace boost{
|
||||||
|
|
||||||
namespace my_conditions {
|
namespace my_conditions {
|
||||||
BOOST_STATIC_ASSERT(sizeof(int) * CHAR_BIT >= 32);
|
BOOST_STATIC_ASSERT(std::numeric_limits<int>::digits >= 32);
|
||||||
BOOST_STATIC_ASSERT(WCHAR_MIN >= 0);
|
BOOST_STATIC_ASSERT(WCHAR_MIN >= 0);
|
||||||
|
|
||||||
} // namespace my_conditions
|
} // namespace my_conditions
|
||||||
@ -30,3 +31,4 @@ int main()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,8 +13,8 @@ template <class UnsignedInt>
|
|||||||
class myclass
|
class myclass
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
BOOST_STATIC_ASSERT(sizeof(UnsignedInt) * CHAR_BIT >= 16);
|
BOOST_STATIC_ASSERT((std::numeric_limits<UnsignedInt>::digits >= 16)
|
||||||
BOOST_STATIC_ASSERT(std::numeric_limits<UnsignedInt>::is_specialized
|
&& std::numeric_limits<UnsignedInt>::is_specialized
|
||||||
&& std::numeric_limits<UnsignedInt>::is_integer
|
&& std::numeric_limits<UnsignedInt>::is_integer
|
||||||
&& !std::numeric_limits<UnsignedInt>::is_signed);
|
&& !std::numeric_limits<UnsignedInt>::is_signed);
|
||||||
public:
|
public:
|
||||||
@ -30,3 +30,4 @@ int main()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user