forked from boostorg/endian
Enable scoped enums in endian_reverse
This commit is contained in:
@ -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>
|
||||
{
|
||||
};
|
||||
|
||||
|
@ -98,3 +98,5 @@ run order_test.cpp ;
|
||||
run endian_reverse_test2.cpp ;
|
||||
|
||||
run is_scoped_enum_test.cpp ;
|
||||
|
||||
run endian_reverse_test3.cpp ;
|
||||
|
62
test/endian_reverse_test3.cpp
Normal file
62
test/endian_reverse_test3.cpp
Normal 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();
|
||||
}
|
Reference in New Issue
Block a user