diff --git a/include/boost/endian/conversion.hpp b/include/boost/endian/conversion.hpp index e03c827..8c11cbb 100644 --- a/include/boost/endian/conversion.hpp +++ b/include/boost/endian/conversion.hpp @@ -46,7 +46,8 @@ namespace endian // reverse byte order // requires T to be a non-bool integral type // in detail/endian_reverse.hpp - template inline BOOST_CONSTEXPR T endian_reverse( T x ) BOOST_NOEXCEPT; + // + // template inline BOOST_CONSTEXPR T endian_reverse( T x ) BOOST_NOEXCEPT; // reverse byte order unless native endianness is big template @@ -109,9 +110,11 @@ namespace endian // reverse in place // in detail/endian_reverse.hpp - template - inline void endian_reverse_inplace(EndianReversible& x) BOOST_NOEXCEPT; - // Effects: x = endian_reverse(x) + // + // template + // inline void endian_reverse_inplace(EndianReversible& x) BOOST_NOEXCEPT; + // + // Effects: x = endian_reverse(x) // reverse in place unless native endianness is big template diff --git a/include/boost/endian/detail/endian_reverse.hpp b/include/boost/endian/detail/endian_reverse.hpp index 88fcf20..2033fca 100644 --- a/include/boost/endian/detail/endian_reverse.hpp +++ b/include/boost/endian/detail/endian_reverse.hpp @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include #include #include @@ -106,7 +108,9 @@ inline uint128_type BOOST_ENDIAN_CONSTEXPR endian_reverse_impl( uint128_type x ) // Requires: // T is non-bool integral -template inline BOOST_CONSTEXPR T endian_reverse( T x ) BOOST_NOEXCEPT +template inline BOOST_CONSTEXPR + typename enable_if_< !is_class::value, T >::type + endian_reverse( T x ) BOOST_NOEXCEPT { BOOST_STATIC_ASSERT( is_integral::value && !(is_same::value) ); diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 5f98443..6771114 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -94,3 +94,5 @@ run endian_hpp_test.cpp ; run-ni endian_hpp_test.cpp ; run order_test.cpp ; + +run endian_reverse_test2.cpp ; diff --git a/test/endian_reverse_test2.cpp b/test/endian_reverse_test2.cpp new file mode 100644 index 0000000..fa31942 --- /dev/null +++ b/test/endian_reverse_test2.cpp @@ -0,0 +1,39 @@ +// Copyright 2019, 2020 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include +#include +#include + +namespace N +{ + +struct X +{ + boost::uint32_t m; +}; + +template typename boost::enable_if_::value, T>::type endian_reverse( T x ) +{ + using boost::endian::endian_reverse; + + X r = { endian_reverse( x.m ) }; + return r; +} + +} // namespace N + +int main() +{ + using namespace boost::endian; + + N::X x1 = { 0x01020304 }; + N::X x2 = endian_reverse( x1 ); + + BOOST_TEST_EQ( x2.m, 0x04030201 ); + + return boost::report_errors(); +}