| 1 | // constexpr test for boost/core/bit.hpp (has_single_bit) |
|---|---|
| 2 | // |
| 3 | // Copyright 2023 Peter Dimov |
| 4 | // Distributed under the Boost Software License, Version 1.0. |
| 5 | // https://www.boost.org/LICENSE_1_0.txt |
| 6 | |
| 7 | #include <boost/config.hpp> |
| 8 | #include <boost/config/pragma_message.hpp> |
| 9 | |
| 10 | #if defined(BOOST_NO_CXX14_CONSTEXPR) |
| 11 | |
| 12 | BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined") |
| 13 | |
| 14 | #else |
| 15 | |
| 16 | #include <boost/core/bit.hpp> |
| 17 | |
| 18 | #define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) |
| 19 | |
| 20 | STATIC_ASSERT( boost::core::has_single_bit( (unsigned char)0x80 ) == true ); |
| 21 | STATIC_ASSERT( boost::core::has_single_bit( (unsigned char)0x90 ) == false ); |
| 22 | |
| 23 | STATIC_ASSERT( boost::core::has_single_bit( (unsigned short)0x8000 ) == true ); |
| 24 | STATIC_ASSERT( boost::core::has_single_bit( (unsigned short)0x9000 ) == false ); |
| 25 | |
| 26 | STATIC_ASSERT( boost::core::has_single_bit( 0x800000u ) == true ); |
| 27 | STATIC_ASSERT( boost::core::has_single_bit( 0x900000u ) == false ); |
| 28 | |
| 29 | STATIC_ASSERT( boost::core::has_single_bit( 0x80000000ul ) == true ); |
| 30 | STATIC_ASSERT( boost::core::has_single_bit( 0x90000000ul ) == false ); |
| 31 | |
| 32 | STATIC_ASSERT( boost::core::has_single_bit( 0x8000000000ull ) == true ); |
| 33 | STATIC_ASSERT( boost::core::has_single_bit( 0x9000000000ull ) == false ); |
| 34 | |
| 35 | #endif |
| 36 |
