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
12BOOST_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
20STATIC_ASSERT( boost::core::has_single_bit( (unsigned char)0x80 ) == true );
21STATIC_ASSERT( boost::core::has_single_bit( (unsigned char)0x90 ) == false );
22
23STATIC_ASSERT( boost::core::has_single_bit( (unsigned short)0x8000 ) == true );
24STATIC_ASSERT( boost::core::has_single_bit( (unsigned short)0x9000 ) == false );
25
26STATIC_ASSERT( boost::core::has_single_bit( 0x800000u ) == true );
27STATIC_ASSERT( boost::core::has_single_bit( 0x900000u ) == false );
28
29STATIC_ASSERT( boost::core::has_single_bit( 0x80000000ul ) == true );
30STATIC_ASSERT( boost::core::has_single_bit( 0x90000000ul ) == false );
31
32STATIC_ASSERT( boost::core::has_single_bit( 0x8000000000ull ) == true );
33STATIC_ASSERT( boost::core::has_single_bit( 0x9000000000ull ) == false );
34
35#endif
36

source code of boost/libs/core/test/has_single_bit_test_cx.cpp