mirror of
https://github.com/boostorg/static_assert.git
synced 2026-05-27 19:24:51 +02:00
Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 46b4482b2f | |||
| 9d3c2ed75f | |||
| 38b5799e33 | |||
| 22bb032a79 | |||
| f2725b11af | |||
| 3ab5f7708e | |||
| 07628a01a7 | |||
| 10425f4864 | |||
| 3bfec69135 | |||
| 90ff3895af | |||
| b776265f02 | |||
| a674ac4176 | |||
| 2b67e5a182 | |||
| 8b37ed2072 | |||
| a947d4039a | |||
| 976f1c78a5 | |||
| 5d68bc2fd8 | |||
| 362a22e3a7 | |||
| 1cd7ee8570 | |||
| cb09a717dd | |||
| e26b873c29 | |||
| fa0ce33cc6 | |||
| 42013c6295 | |||
| 8cb6da5df0 |
@@ -0,0 +1,16 @@
|
||||
subproject libs/static_assert ;
|
||||
|
||||
|
||||
unit-test static_assert_test : static_assert_test.cpp
|
||||
: <sysinclude>$(BOOST_ROOT) : ;
|
||||
|
||||
unit-test static_assert_example_1 : static_assert_example_1.cpp
|
||||
: <sysinclude>$(BOOST_ROOT) : ;
|
||||
|
||||
unit-test static_assert_example_2 : static_assert_example_2.cpp
|
||||
: <sysinclude>$(BOOST_ROOT) : ;
|
||||
|
||||
unit-test static_assert_example_3 : static_assert_example_3.cpp
|
||||
: <sysinclude>$(BOOST_ROOT) : ;
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
/*
|
||||
Revision history:
|
||||
02 August 2000
|
||||
Initial version.
|
||||
02 August 2000
|
||||
Initial version.
|
||||
*/
|
||||
|
||||
#ifndef BOOST_STATIC_ASSERT_HPP
|
||||
@@ -25,11 +25,13 @@
|
||||
|
||||
namespace boost{
|
||||
|
||||
template <bool> struct STATIC_ASSERTION_FAILURE;
|
||||
// HP aCC cannot deal with missing names for template value parameters
|
||||
template <bool x> struct STATIC_ASSERTION_FAILURE;
|
||||
|
||||
template <> struct STATIC_ASSERTION_FAILURE<true>{};
|
||||
|
||||
template<int> struct static_assert_test{};
|
||||
// HP aCC cannot deal with missing names for template value parameters
|
||||
template<int x> struct static_assert_test{};
|
||||
|
||||
}
|
||||
|
||||
@@ -51,37 +53,31 @@ template<int> struct static_assert_test{};
|
||||
// an eye catching error message. The result of the sizeof expression is either
|
||||
// used as an enum initialiser, or as a template argument depending which version
|
||||
// is in use...
|
||||
// Note that the argument to the assert is explicitly cast to bool using old-
|
||||
// style casts: too many compilers currently have problems with static_cast
|
||||
// when used inside integral constant expressions.
|
||||
//
|
||||
#if !defined(BOOST_BUGGY_INTEGRAL_CONSTANT_EXPRESSIONS) && !defined(__MWERKS__)
|
||||
#ifndef BOOST_MSVC
|
||||
#define BOOST_STATIC_ASSERT( B ) \
|
||||
typedef ::boost::static_assert_test<\
|
||||
sizeof(::boost::STATIC_ASSERTION_FAILURE< ( B ) >)>\
|
||||
BOOST_ASSERT_JOIN(boost_static_assert_typedef_, __LINE__)
|
||||
sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >)>\
|
||||
BOOST_JOIN(boost_static_assert_typedef_, __LINE__)
|
||||
#else
|
||||
// __LINE__ macro broken when -ZI is used see Q199057
|
||||
// fortunately MSVC ignores duplicate typedef's.
|
||||
#define BOOST_STATIC_ASSERT( B ) \
|
||||
typedef ::boost::static_assert_test<\
|
||||
sizeof(::boost::STATIC_ASSERTION_FAILURE< ( B ) >)\
|
||||
sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >)\
|
||||
> boost_static_assert_typedef_
|
||||
#endif
|
||||
#else
|
||||
// alternative enum based implementation:
|
||||
#define BOOST_STATIC_ASSERT( B ) \
|
||||
enum { BOOST_ASSERT_JOIN(boost_static_assert_enum_, __LINE__) \
|
||||
= sizeof(::boost::STATIC_ASSERTION_FAILURE< ( B ) >) }
|
||||
enum { BOOST_JOIN(boost_static_assert_enum_, __LINE__) \
|
||||
= sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >) }
|
||||
#endif
|
||||
|
||||
//
|
||||
// The following piece of macro magic joins the two
|
||||
// arguments together, even when one of the arguments is
|
||||
// itself a macro (see 16.3.1 in C++ standard). The key
|
||||
// is that macro expansion of macro arguments does not
|
||||
// occur in BOOST_DO_ASSERT_JOIN but does in BOOST_ASSERT_JOIN
|
||||
// provided it is called from within another macro.
|
||||
#define BOOST_ASSERT_JOIN( X, Y ) BOOST_DO_ASSERT_JOIN( X, Y )
|
||||
#define BOOST_DO_ASSERT_JOIN( X, Y ) X##Y
|
||||
|
||||
#endif // BOOST_STATIC_ASSERT_HPP
|
||||
|
||||
|
||||
+5
-4
@@ -5,7 +5,7 @@
|
||||
content="text/html; charset=iso-8859-1">
|
||||
<meta name="Template"
|
||||
content="C:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE\html.dot">
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
|
||||
<title>static assertions</title>
|
||||
</head>
|
||||
|
||||
@@ -18,7 +18,7 @@ vlink="#800080">
|
||||
<p>The header <boost/static_assert.hpp> supplies a single
|
||||
macro BOOST_STATIC_ASSERT(x), which generates a compile time
|
||||
error message if the <a
|
||||
href="../../more/integral_constant_guidelines.htm">integral-constant-expression</a>
|
||||
href="../../more/int_const_guidelines.htm">integral-constant-expression</a>
|
||||
<i>x</i> is not true. In other words it is the compile time
|
||||
equivalent of the assert macro; this is sometimes known as a
|
||||
"compile-time-assertion", but will be called a "static
|
||||
@@ -131,7 +131,7 @@ argument, we can achieve this using something like this:</p>
|
||||
<pre>#include <climits>
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
Template <class UnsignedInt>template <class UnsignedInt>
|
||||
template <class UnsignedInt>
|
||||
class myclass
|
||||
{
|
||||
private:
|
||||
@@ -268,7 +268,8 @@ warranty, and with no claim as to its suitability for any purpose.</p>
|
||||
<p>Maintained by <a href="mailto:John_Maddock@compuserve.com">John
|
||||
Maddock</a>, the latest version of this file can be found at <a
|
||||
href="http://www.boost.org/">www.boost.org</a>, and the boost
|
||||
discussion list at <a href="http://www.yahoogroups.com/list/boost">www.yahoogroups.com/list/boost</a>.
|
||||
discussion list at <a
|
||||
href="http://www.yahoogroups.com/list/boost">www.yahoogroups.com/list/boost</a>.
|
||||
</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <cwchar>
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
#if defined(__BORLANDC__) && !defined(WCHAR_MIN)
|
||||
#if !defined(WCHAR_MIN)
|
||||
#define WCHAR_MIN 0
|
||||
#endif
|
||||
|
||||
@@ -29,3 +29,4 @@ int main()
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -26,11 +26,11 @@ RandomAccessIterator foo(RandomAccessIterator from, RandomAccessIterator to)
|
||||
|
||||
int main()
|
||||
{
|
||||
std::deque<int> d;
|
||||
std::list<int> l;
|
||||
foo(d.begin(), d.end()); // OK
|
||||
//foo(l.begin(), l.end()); // error
|
||||
return 0;
|
||||
std::deque<int> d;
|
||||
std::list<int> l;
|
||||
foo(d.begin(), d.end()); // OK
|
||||
//foo(l.begin(), l.end()); // error
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -13,10 +13,6 @@
|
||||
// all these tests should fail:
|
||||
//
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#error "VC6 not supported in this test (buggy compiler problem)"
|
||||
#endif
|
||||
|
||||
|
||||
struct Bob
|
||||
{
|
||||
@@ -27,7 +23,7 @@ struct Bob
|
||||
char c;
|
||||
int f()
|
||||
{
|
||||
#ifndef _MSC_VER // broken sizeof in VC6
|
||||
#if !defined(BOOST_MSVC) || BOOST_MSVC > 1200 // broken sizeof in VC6
|
||||
BOOST_STATIC_ASSERT(sizeof(x) == 4);
|
||||
BOOST_STATIC_ASSERT(sizeof(c) == 1);
|
||||
BOOST_STATIC_ASSERT((sizeof(x) == sizeof(c))); // should not compile
|
||||
|
||||
@@ -12,12 +12,12 @@
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/type_traits.hpp>
|
||||
|
||||
template <class RandonAccessIterator >
|
||||
RandonAccessIterator foo(RandonAccessIterator from, RandonAccessIterator to)
|
||||
template <class RandomAccessIterator >
|
||||
RandomAccessIterator foo(RandomAccessIterator from, RandomAccessIterator)
|
||||
{
|
||||
// this template can only be used with
|
||||
// random access iterators...
|
||||
typedef typename std::iterator_traits< RandonAccessIterator >::iterator_category cat;
|
||||
typedef typename std::iterator_traits< RandomAccessIterator >::iterator_category cat;
|
||||
BOOST_STATIC_ASSERT((boost::is_convertible<cat*, std::random_access_iterator_tag*>::value));
|
||||
//
|
||||
// detail goes here...
|
||||
@@ -26,11 +26,11 @@ RandonAccessIterator foo(RandonAccessIterator from, RandonAccessIterator to)
|
||||
|
||||
int main()
|
||||
{
|
||||
std::deque<int> d;
|
||||
std::list<int> l;
|
||||
foo(d.begin(), d.end()); // OK
|
||||
foo(l.begin(), l.end()); // error
|
||||
return 0;
|
||||
std::deque<int> d;
|
||||
std::list<int> l;
|
||||
foo(d.begin(), d.end()); // OK
|
||||
foo(l.begin(), l.end()); // error
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user