forked from boostorg/static_assert
Compare commits
8 Commits
svn-branch
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
dd82fb3118 | |||
8b819d5c6c | |||
bc5065e495 | |||
1663a635aa | |||
b9a3b24aef | |||
a0dac351fb | |||
c68b2114de | |||
48b6934f7f |
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
|
||||
# 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
|
||||
import testing ;
|
||||
@ -25,3 +28,4 @@ test-suite static_assert :
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -15,6 +15,10 @@
|
||||
[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]
|
||||
|
||||
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 <cwchar>
|
||||
#include <limits>
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
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);
|
||||
|
||||
} // 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 macro `BOOST_STATIC_ASSERT` works by generating an typedef declaration,
|
||||
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`
|
||||
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
|
||||
@ -93,12 +98,17 @@ the user that the template is being misused.
|
||||
#include <boost/type_traits.hpp>
|
||||
|
||||
template <class RandomAccessIterator >
|
||||
RandomAccessIterator foo(RandomAccessIterator from, RandomAccessIterator to)
|
||||
RandomAccessIterator foo(RandomAccessIterator from,
|
||||
RandomAccessIterator to)
|
||||
{
|
||||
// this template can only be used with
|
||||
// random access iterators...
|
||||
typedef typename std::iterator_traits< RandomAccessIterator >::iterator_category cat;
|
||||
BOOST_STATIC_ASSERT((boost::is_convertible<cat, const std::random_access_iterator_tag&>::value));
|
||||
typedef typename std::iterator_traits<
|
||||
RandomAccessIterator >::iterator_category cat;
|
||||
BOOST_STATIC_ASSERT(
|
||||
(boost::is_convertible<
|
||||
cat,
|
||||
const std::random_access_iterator_tag&>::value));
|
||||
//
|
||||
// detail goes here...
|
||||
return from;
|
||||
@ -128,8 +138,8 @@ using something like this:
|
||||
class myclass
|
||||
{
|
||||
private:
|
||||
BOOST_STATIC_ASSERT(sizeof(UnsignedInt) * CHAR_BIT >= 16);
|
||||
BOOST_STATIC_ASSERT(std::numeric_limits<UnsignedInt>::is_specialized
|
||||
BOOST_STATIC_ASSERT((std::numeric_limits<UnsignedInt>::digits >= 16)
|
||||
&& std::numeric_limits<UnsignedInt>::is_specialized
|
||||
&& std::numeric_limits<UnsignedInt>::is_integer
|
||||
&& !std::numeric_limits<UnsignedInt>::is_signed);
|
||||
public:
|
||||
@ -216,3 +226,5 @@ working at namespace, function, and class scope outweighed the ugliness of a mac
|
||||
]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
|
@ -28,6 +28,20 @@
|
||||
# define BOOST_SA_GCC_WORKAROUND
|
||||
#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{
|
||||
|
||||
// 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)
|
||||
#define BOOST_STATIC_ASSERT( B ) \
|
||||
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__)
|
||||
#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
|
||||
// instead of warning in case of failure
|
||||
# define BOOST_STATIC_ASSERT( B ) \
|
||||
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)
|
||||
// special version for SGI MIPSpro compiler
|
||||
#define BOOST_STATIC_ASSERT( B ) \
|
||||
@ -96,12 +110,12 @@ template<int x> struct static_assert_test{};
|
||||
#define BOOST_STATIC_ASSERT( B ) \
|
||||
BOOST_STATIC_CONSTANT(int, \
|
||||
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
|
||||
// generic version
|
||||
#define BOOST_STATIC_ASSERT( B ) \
|
||||
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__)
|
||||
#endif
|
||||
|
||||
@ -111,7 +125,7 @@ template<int x> struct static_assert_test{};
|
||||
enum { BOOST_JOIN(boost_static_assert_enum_, __LINE__) \
|
||||
= sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >) }
|
||||
#endif
|
||||
|
||||
#endif // ndef BOOST_HAS_STATIC_ASSERT
|
||||
|
||||
#endif // BOOST_STATIC_ASSERT_HPP
|
||||
|
||||
|
@ -9,6 +9,10 @@
|
||||
or view the online version at
|
||||
<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>
|
||||
<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>
|
||||
</html>
|
||||
|
||||
|
||||
|
@ -9,6 +9,10 @@
|
||||
or view the online version at
|
||||
<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>
|
||||
<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>
|
||||
</html>
|
||||
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include <climits>
|
||||
#include <cwchar>
|
||||
#include <limits>
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
#if !defined(WCHAR_MIN)
|
||||
@ -16,7 +17,7 @@
|
||||
namespace boost{
|
||||
|
||||
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);
|
||||
|
||||
} // namespace my_conditions
|
||||
@ -30,3 +31,4 @@ int main()
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -13,8 +13,8 @@ template <class UnsignedInt>
|
||||
class myclass
|
||||
{
|
||||
private:
|
||||
BOOST_STATIC_ASSERT(sizeof(UnsignedInt) * CHAR_BIT >= 16);
|
||||
BOOST_STATIC_ASSERT(std::numeric_limits<UnsignedInt>::is_specialized
|
||||
BOOST_STATIC_ASSERT((std::numeric_limits<UnsignedInt>::digits >= 16)
|
||||
&& std::numeric_limits<UnsignedInt>::is_specialized
|
||||
&& std::numeric_limits<UnsignedInt>::is_integer
|
||||
&& !std::numeric_limits<UnsignedInt>::is_signed);
|
||||
public:
|
||||
@ -30,3 +30,4 @@ int main()
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user