• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 namespace N
12 {
13 
14 struct X
15 {
16     boost::uint32_t m;
17 };
18 
endian_reverse(T x)19 template<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 
main()29 int main()
30 {
31     using namespace boost::endian;
32 
33     N::X x1 = { 0x01020304 };
34     N::X x2 = endian_reverse( x1 );
35 
36     BOOST_TEST_EQ( x2.m, 0x04030201 );
37 
38     return boost::report_errors();
39 }
40