Enable scoped enums in endian_reverse

This commit is contained in:
Peter Dimov
2020-05-03 00:10:06 +03:00
parent 74b73c5c03
commit 8e617a69d1
3 changed files with 67 additions and 2 deletions

View File

@ -8,6 +8,7 @@
#include <boost/endian/detail/integral_by_size.hpp>
#include <boost/endian/detail/intrinsic.hpp>
#include <boost/endian/detail/is_scoped_enum.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/enable_if.hpp>
@ -107,14 +108,14 @@ inline uint128_type BOOST_ENDIAN_CONSTEXPR endian_reverse_impl( uint128_type x )
// is_endian_reversible
template<class T> struct is_endian_reversible: boost::integral_constant<bool,
boost::is_integral<T>::value && !boost::is_same<T, bool>::value>
(boost::is_integral<T>::value && !boost::is_same<T, bool>::value) || is_scoped_enum<T>::value>
{
};
// is_endian_reversible_inplace
template<class T> struct is_endian_reversible_inplace: boost::integral_constant<bool,
boost::is_integral<T>::value && !boost::is_same<T, bool>::value>
(boost::is_integral<T>::value && !boost::is_same<T, bool>::value) || is_scoped_enum<T>::value>
{
};

View File

@ -98,3 +98,5 @@ run order_test.cpp ;
run endian_reverse_test2.cpp ;
run is_scoped_enum_test.cpp ;
run endian_reverse_test3.cpp ;

View File

@ -0,0 +1,62 @@
// Copyright 2020 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/endian/conversion.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config.hpp>
#include <cstddef>
template<class T> void test_reverse( T x )
{
using boost::endian::endian_reverse;
T x2 = endian_reverse( endian_reverse( x ) );
BOOST_TEST( x == x2 );
}
template<class T> void test_reverse_inplace( T x )
{
using boost::endian::endian_reverse_inplace;
T x2( x );
endian_reverse_inplace( x2 );
endian_reverse_inplace( x2 );
BOOST_TEST( x == x2 );
}
enum E1 { e1 };
#if !defined(BOOST_NO_CXX11_SCOPED_ENUMS)
enum E2: long { e2 };
enum class E3 { e3 };
enum class E4: long { e4 };
#endif
int main()
{
test_reverse( 1 );
#if !defined(BOOST_NO_CXX11_SCOPED_ENUMS)
test_reverse( E3::e3 );
test_reverse( E4::e4 );
#endif
test_reverse_inplace( 1 );
#if !defined(BOOST_NO_CXX11_SCOPED_ENUMS)
test_reverse_inplace( E3::e3 );
test_reverse_inplace( E4::e4 );
#endif
return boost::report_errors();
}