forked from boostorg/endian
Enable conditional_reverse_inplace for arrays
This commit is contained in:
@ -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 )
|
||||
{
|
||||
|
@ -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 ;
|
||||
|
30
test/endian_reverse_test5.cpp
Normal file
30
test/endian_reverse_test5.cpp
Normal 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();
|
||||
}
|
Reference in New Issue
Block a user