1// Copyright 2019, 2020 Peter Dimov
2// Distributed under the Boost Software License, Version 1.0.
3// http://www.boost.org/LICENSE_1_0.txt
4
5#include <boost/endian/conversion.hpp>
6#include <boost/core/lightweight_test.hpp>
7#include <boost/type_traits/enable_if.hpp>
8#include <boost/type_traits/is_same.hpp>
9#include <boost/cstdint.hpp>
10
11namespace N
12{
13
14struct X
15{
16 boost::uint32_t m;
17};
18
19template<class T> typename boost::enable_if_<boost::is_same<T, X>::value, T>::type endian_reverse( T x )
20{
21 using boost::endian::endian_reverse;
22
23 X r = { endian_reverse( x.m ) };
24 return r;
25}
26
27} // namespace N
28
29int main()
30{
31 using namespace boost::endian;
32
33 N::X x1 = { .m: 0x01020304 };
34 N::X x2 = endian_reverse( x: x1 );
35
36 BOOST_TEST_EQ( x2.m, 0x04030201 );
37
38 return boost::report_errors();
39}
40

source code of boost/libs/endian/test/endian_reverse_test2.cpp