From 9ee301b103ff70d9a7767a1f27561851a3bce0dc Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 5 May 2020 21:24:02 +0300 Subject: [PATCH] Enable conditional_reverse_inplace for arrays --- include/boost/endian/conversion.hpp | 12 ++++++++++-- test/Jamfile.v2 | 3 +++ test/endian_reverse_test5.cpp | 30 +++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 test/endian_reverse_test5.cpp diff --git a/include/boost/endian/conversion.hpp b/include/boost/endian/conversion.hpp index 58aaa4a..2104ae4 100644 --- a/include/boost/endian/conversion.hpp +++ b/include/boost/endian/conversion.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -249,7 +250,11 @@ inline void conditional_reverse_inplace_impl( EndianReversibleInplace& x, boost: template inline void conditional_reverse_inplace( EndianReversibleInplace& x ) BOOST_NOEXCEPT { - BOOST_STATIC_ASSERT( boost::is_class::value || detail::is_endian_reversible_inplace::value ); + BOOST_STATIC_ASSERT( + boost::is_class::value || + boost::is_array::value || + detail::is_endian_reversible_inplace::value ); + detail::conditional_reverse_inplace_impl( x, boost::integral_constant() ); } @@ -258,7 +263,10 @@ template 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::value || detail::is_endian_reversible_inplace::value ); + BOOST_STATIC_ASSERT( + boost::is_class::value || + boost::is_array::value || + detail::is_endian_reversible_inplace::value ); if( from_order != to_order ) { diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index f5672bd..cde5d12 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -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 ; diff --git a/test/endian_reverse_test5.cpp b/test/endian_reverse_test5.cpp new file mode 100644 index 0000000..5273795 --- /dev/null +++ b/test/endian_reverse_test5.cpp @@ -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 +#include +#include +#include + +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(); +}