Enable conditional_reverse_inplace for arrays

This commit is contained in:
Peter Dimov
2020-05-05 21:24:02 +03:00
parent d46d2916a8
commit 9ee301b103
3 changed files with 43 additions and 2 deletions

View File

@ -13,6 +13,7 @@
#include <boost/endian/detail/endian_store.hpp>
#include <boost/endian/detail/order.hpp>
#include <boost/type_traits/is_class.hpp>
#include <boost/type_traits/is_array.hpp>
#include <boost/type_traits/integral_constant.hpp>
#include <boost/static_assert.hpp>
#include <boost/cstdint.hpp>
@ -249,7 +250,11 @@ inline void conditional_reverse_inplace_impl( EndianReversibleInplace& x, boost:
template <BOOST_SCOPED_ENUM(order) From, BOOST_SCOPED_ENUM(order) To, class EndianReversibleInplace>
inline void conditional_reverse_inplace( EndianReversibleInplace& x ) BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT( boost::is_class<EndianReversibleInplace>::value || detail::is_endian_reversible_inplace<EndianReversibleInplace>::value );
BOOST_STATIC_ASSERT(
boost::is_class<EndianReversibleInplace>::value ||
boost::is_array<EndianReversibleInplace>::value ||
detail::is_endian_reversible_inplace<EndianReversibleInplace>::value );
detail::conditional_reverse_inplace_impl( x, boost::integral_constant<bool, From == To>() );
}
@ -258,7 +263,10 @@ template <class EndianReversibleInplace>
inline void conditional_reverse_inplace( EndianReversibleInplace& x,
BOOST_SCOPED_ENUM(order) from_order, BOOST_SCOPED_ENUM(order) to_order ) BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT( boost::is_class<EndianReversibleInplace>::value || detail::is_endian_reversible_inplace<EndianReversibleInplace>::value );
BOOST_STATIC_ASSERT(
boost::is_class<EndianReversibleInplace>::value ||
boost::is_array<EndianReversibleInplace>::value ||
detail::is_endian_reversible_inplace<EndianReversibleInplace>::value );
if( from_order != to_order )
{

View File

@ -105,3 +105,6 @@ run-ni endian_reverse_test3.cpp ;
run endian_reverse_test4.cpp ;
run-ni endian_reverse_test4.cpp ;
run endian_reverse_test5.cpp ;
run-ni endian_reverse_test5.cpp ;

View File

@ -0,0 +1,30 @@
// 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>
int main()
{
int v[] = { 1, 2 };
boost::endian::endian_reverse_inplace( v );
boost::endian::endian_reverse_inplace( v );
BOOST_TEST_EQ( v[0], 1 );
BOOST_TEST_EQ( v[1], 2 );
boost::endian::native_to_little_inplace( v );
boost::endian::little_to_native_inplace( v );
BOOST_TEST_EQ( v[0], 1 );
BOOST_TEST_EQ( v[1], 2 );
boost::endian::native_to_big_inplace( v );
boost::endian::big_to_native_inplace( v );
BOOST_TEST_EQ( v[0], 1 );
BOOST_TEST_EQ( v[1], 2 );
return boost::report_errors();
}