forked from boostorg/static_assert
Added trivial docs change, based on user suggestion, and brought example code into synch.
[SVN r34874]
This commit is contained in:
@ -49,11 +49,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 +62,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
|
||||||
@ -128,8 +129,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 +217,5 @@ working at namespace, function, and class scope outweighed the ugliness of a mac
|
|||||||
]
|
]
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
|
|
||||||
|
@ -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