mirror of
https://github.com/boostorg/static_assert.git
synced 2025-06-27 21:11:01 +02:00
Compare commits
11 Commits
boost-1.23
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
46b4482b2f | |||
9d3c2ed75f | |||
38b5799e33 | |||
22bb032a79 | |||
f2725b11af | |||
3ab5f7708e | |||
07628a01a7 | |||
10425f4864 | |||
3bfec69135 | |||
90ff3895af | |||
b776265f02 |
16
Jamfile
Normal file
16
Jamfile
Normal file
@ -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:
|
Revision history:
|
||||||
02 August 2000
|
02 August 2000
|
||||||
Initial version.
|
Initial version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef BOOST_STATIC_ASSERT_HPP
|
#ifndef BOOST_STATIC_ASSERT_HPP
|
||||||
@ -62,7 +62,7 @@ template<int x> struct static_assert_test{};
|
|||||||
#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< (bool)( B ) >)>\
|
||||||
BOOST_ASSERT_JOIN(boost_static_assert_typedef_, __LINE__)
|
BOOST_JOIN(boost_static_assert_typedef_, __LINE__)
|
||||||
#else
|
#else
|
||||||
// __LINE__ macro broken when -ZI is used see Q199057
|
// __LINE__ macro broken when -ZI is used see Q199057
|
||||||
// fortunately MSVC ignores duplicate typedef's.
|
// fortunately MSVC ignores duplicate typedef's.
|
||||||
@ -74,19 +74,10 @@ template<int x> struct static_assert_test{};
|
|||||||
#else
|
#else
|
||||||
// alternative enum based implementation:
|
// alternative enum based implementation:
|
||||||
#define BOOST_STATIC_ASSERT( B ) \
|
#define BOOST_STATIC_ASSERT( B ) \
|
||||||
enum { BOOST_ASSERT_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
|
||||||
|
|
||||||
//
|
|
||||||
// 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
|
#endif // BOOST_STATIC_ASSERT_HPP
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ argument, we can achieve this using something like this:</p>
|
|||||||
<pre>#include <climits>
|
<pre>#include <climits>
|
||||||
#include <boost/static_assert.hpp>
|
#include <boost/static_assert.hpp>
|
||||||
|
|
||||||
Template <class UnsignedInt>template <class UnsignedInt>
|
template <class UnsignedInt>
|
||||||
class myclass
|
class myclass
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#include <cwchar>
|
#include <cwchar>
|
||||||
#include <boost/static_assert.hpp>
|
#include <boost/static_assert.hpp>
|
||||||
|
|
||||||
#if defined(__BORLANDC__) && !defined(WCHAR_MIN)
|
#if !defined(WCHAR_MIN)
|
||||||
#define WCHAR_MIN 0
|
#define WCHAR_MIN 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -29,3 +29,4 @@ int main()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,11 +26,11 @@ RandomAccessIterator foo(RandomAccessIterator from, RandomAccessIterator to)
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
std::deque<int> d;
|
std::deque<int> d;
|
||||||
std::list<int> l;
|
std::list<int> l;
|
||||||
foo(d.begin(), d.end()); // OK
|
foo(d.begin(), d.end()); // OK
|
||||||
//foo(l.begin(), l.end()); // error
|
//foo(l.begin(), l.end()); // error
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,10 +13,6 @@
|
|||||||
// all these tests should fail:
|
// all these tests should fail:
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifdef BOOST_MSVC
|
|
||||||
#error "VC6 not supported in this test (buggy compiler problem)"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
struct Bob
|
struct Bob
|
||||||
{
|
{
|
||||||
@ -27,7 +23,7 @@ struct Bob
|
|||||||
char c;
|
char c;
|
||||||
int f()
|
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(x) == 4);
|
||||||
BOOST_STATIC_ASSERT(sizeof(c) == 1);
|
BOOST_STATIC_ASSERT(sizeof(c) == 1);
|
||||||
BOOST_STATIC_ASSERT((sizeof(x) == sizeof(c))); // should not compile
|
BOOST_STATIC_ASSERT((sizeof(x) == sizeof(c))); // should not compile
|
||||||
|
@ -12,12 +12,12 @@
|
|||||||
#include <boost/static_assert.hpp>
|
#include <boost/static_assert.hpp>
|
||||||
#include <boost/type_traits.hpp>
|
#include <boost/type_traits.hpp>
|
||||||
|
|
||||||
template <class RandonAccessIterator >
|
template <class RandomAccessIterator >
|
||||||
RandonAccessIterator foo(RandonAccessIterator from, RandonAccessIterator to)
|
RandomAccessIterator foo(RandomAccessIterator from, RandomAccessIterator)
|
||||||
{
|
{
|
||||||
// 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< 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));
|
BOOST_STATIC_ASSERT((boost::is_convertible<cat*, std::random_access_iterator_tag*>::value));
|
||||||
//
|
//
|
||||||
// detail goes here...
|
// detail goes here...
|
||||||
@ -26,11 +26,11 @@ RandonAccessIterator foo(RandonAccessIterator from, RandonAccessIterator to)
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
std::deque<int> d;
|
std::deque<int> d;
|
||||||
std::list<int> l;
|
std::list<int> l;
|
||||||
foo(d.begin(), d.end()); // OK
|
foo(d.begin(), d.end()); // OK
|
||||||
foo(l.begin(), l.end()); // error
|
foo(l.begin(), l.end()); // error
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user