mirror of
https://github.com/boostorg/static_assert.git
synced 2025-07-14 05:06:33 +02:00
Compare commits
10 Commits
boost-1.26
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
8308b63aa8 | |||
02c6fb40a6 | |||
5ea88d2e64 | |||
1029ee8032 | |||
f2732e699f | |||
9d3c2ed75f | |||
38b5799e33 | |||
22bb032a79 | |||
f2725b11af | |||
3ab5f7708e |
30
Jamfile
30
Jamfile
@ -1,16 +1,22 @@
|
||||
subproject libs/static_assert ;
|
||||
# bring in the rules for testing
|
||||
SEARCH on testing.jam = $(BOOST_BUILD_PATH) ;
|
||||
include testing.jam ;
|
||||
|
||||
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 ]
|
||||
;
|
||||
|
||||
|
||||
unit-test static_assert_test : static_assert_test.cpp
|
||||
: <include>$(BOOST_ROOT) : ;
|
||||
|
||||
unit-test static_assert_example_1 : static_assert_example_1.cpp
|
||||
: <include>$(BOOST_ROOT) : ;
|
||||
|
||||
unit-test static_assert_example_2 : static_assert_example_2.cpp
|
||||
: <include>$(BOOST_ROOT) : ;
|
||||
|
||||
unit-test static_assert_example_3 : static_assert_example_3.cpp
|
||||
: <include>$(BOOST_ROOT) : ;
|
||||
|
||||
|
||||
|
@ -4,12 +4,12 @@
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
// See http://www.boost.org/libs/static_assert for documentation.
|
||||
|
||||
/*
|
||||
Revision history:
|
||||
02 August 2000
|
||||
Initial version.
|
||||
02 August 2000
|
||||
Initial version.
|
||||
*/
|
||||
|
||||
#ifndef BOOST_STATIC_ASSERT_HPP
|
||||
@ -28,7 +28,7 @@ namespace boost{
|
||||
// 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 <> struct STATIC_ASSERTION_FAILURE<true> { enum { value = 1 }; };
|
||||
|
||||
// HP aCC cannot deal with missing names for template value parameters
|
||||
template<int x> struct static_assert_test{};
|
||||
@ -58,19 +58,28 @@ template<int x> struct static_assert_test{};
|
||||
// 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< (bool)( B ) >)>\
|
||||
BOOST_JOIN(boost_static_assert_typedef_, __LINE__)
|
||||
#else
|
||||
|
||||
#if defined(BOOST_MSVC)
|
||||
// __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< (bool)( B ) >)\
|
||||
> boost_static_assert_typedef_
|
||||
#elif defined(BOOST_INTEL_CXX_VERSION)
|
||||
// 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 ]
|
||||
#else
|
||||
// generic version
|
||||
#define BOOST_STATIC_ASSERT( B ) \
|
||||
typedef ::boost::static_assert_test<\
|
||||
sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >)>\
|
||||
BOOST_JOIN(boost_static_assert_typedef_, __LINE__)
|
||||
#endif
|
||||
|
||||
#else
|
||||
// alternative enum based implementation:
|
||||
#define BOOST_STATIC_ASSERT( B ) \
|
||||
@ -80,7 +89,3 @@ template<int x> struct static_assert_test{};
|
||||
|
||||
|
||||
#endif // BOOST_STATIC_ASSERT_HPP
|
||||
|
||||
|
||||
|
||||
|
||||
|
9
index.html
Normal file
9
index.html
Normal file
@ -0,0 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0; URL=static_assert.htm">
|
||||
</head>
|
||||
<body>
|
||||
Automatic redirection failed, please go to
|
||||
<a href="static_assert.htm">static_assert.htm</a>.
|
||||
</body>
|
||||
</html>
|
@ -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:
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,7 +23,7 @@ struct Bob
|
||||
char c;
|
||||
int f()
|
||||
{
|
||||
#ifndef BOOST_MSVC // 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)
|
||||
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)
|
||||
|
||||
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