diff --git a/doc/static_assert.qbk b/doc/static_assert.qbk index da21287..7ff0b58 100644 --- a/doc/static_assert.qbk +++ b/doc/static_assert.qbk @@ -49,11 +49,12 @@ be an unsigned type. We can verify this at compile time as follows: #include #include + #include #include namespace my_conditions { - BOOST_STATIC_ASSERT(sizeof(int) * CHAR_BIT >= 32); + BOOST_STATIC_ASSERT(std::numeric_limits::digits >= 32); BOOST_STATIC_ASSERT(WCHAR_MIN >= 0); } // 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 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 @@ -128,8 +129,8 @@ using something like this: class myclass { private: - BOOST_STATIC_ASSERT(sizeof(UnsignedInt) * CHAR_BIT >= 16); - BOOST_STATIC_ASSERT(std::numeric_limits::is_specialized + BOOST_STATIC_ASSERT((std::numeric_limits::digits >= 16) + && std::numeric_limits::is_specialized && std::numeric_limits::is_integer && !std::numeric_limits::is_signed); public: @@ -216,3 +217,5 @@ working at namespace, function, and class scope outweighed the ugliness of a mac ] [endsect] + + diff --git a/static_assert_example_1.cpp b/static_assert_example_1.cpp index f5efdf7..14c529c 100644 --- a/static_assert_example_1.cpp +++ b/static_assert_example_1.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #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::digits >= 32); BOOST_STATIC_ASSERT(WCHAR_MIN >= 0); } // namespace my_conditions @@ -30,3 +31,4 @@ int main() + diff --git a/static_assert_example_3.cpp b/static_assert_example_3.cpp index cf12ce5..e958131 100644 --- a/static_assert_example_3.cpp +++ b/static_assert_example_3.cpp @@ -13,8 +13,8 @@ template class myclass { private: - BOOST_STATIC_ASSERT(sizeof(UnsignedInt) * CHAR_BIT >= 16); - BOOST_STATIC_ASSERT(std::numeric_limits::is_specialized + BOOST_STATIC_ASSERT((std::numeric_limits::digits >= 16) + && std::numeric_limits::is_specialized && std::numeric_limits::is_integer && !std::numeric_limits::is_signed); public: @@ -30,3 +30,4 @@ int main() return 0; } +