1// constexpr test for boost/core/bit.hpp (bit_width)
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#elif defined(BOOST_MSVC) && BOOST_MSVC / 10 == 191
15
16BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_MSVC is " BOOST_STRINGIZE(BOOST_MSVC) )
17
18#else
19
20#include <boost/core/bit.hpp>
21#include <cstdint>
22
23#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
24
25STATIC_ASSERT( boost::core::byteswap( (std::int8_t)0x01 ) == 0x01 );
26STATIC_ASSERT( boost::core::byteswap( (std::uint8_t)0xF1 ) == 0xF1 );
27
28STATIC_ASSERT( boost::core::byteswap( (std::int16_t)0x0102 ) == 0x0201 );
29STATIC_ASSERT( boost::core::byteswap( (std::uint16_t)0xF1E2 ) == 0xE2F1 );
30
31STATIC_ASSERT( boost::core::byteswap( (std::int32_t)0x01020304 ) == 0x04030201 );
32STATIC_ASSERT( boost::core::byteswap( (std::uint32_t)0xF1E2D3C4u ) == 0xC4D3E2F1u );
33
34STATIC_ASSERT( boost::core::byteswap( (std::int64_t)0x0102030405060708ll ) == 0x0807060504030201ll );
35STATIC_ASSERT( boost::core::byteswap( (std::uint64_t)0xF1E2D3C4B5A69788ull ) == 0x8897A6B5C4D3E2F1ull );
36
37#endif
38

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