From d40a3ac3f4973f5cf81f98dedc460ac83325734e Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 30 Apr 2019 05:13:47 +0300 Subject: [PATCH] Switch the parameter order of endian_store --- include/boost/endian/buffers.hpp | 8 +-- include/boost/endian/conversion.hpp | 2 + include/boost/endian/detail/endian_store.hpp | 40 ++++++------ test/endian_ld_st_roundtrip_test.cpp | 4 +- test/endian_store_test.cpp | 64 ++++++++++---------- 5 files changed, 60 insertions(+), 58 deletions(-) diff --git a/include/boost/endian/buffers.hpp b/include/boost/endian/buffers.hpp index 05aaa0f..46f6eb7 100644 --- a/include/boost/endian/buffers.hpp +++ b/include/boost/endian/buffers.hpp @@ -243,14 +243,14 @@ public: explicit endian_buffer( T val ) BOOST_NOEXCEPT { - boost::endian::endian_store( val, value_ ); + boost::endian::endian_store( value_, val ); } #endif endian_buffer& operator=( T val ) BOOST_NOEXCEPT { - boost::endian::endian_store( val, value_ ); + boost::endian::endian_store( value_, val ); return *this; } @@ -293,14 +293,14 @@ public: explicit endian_buffer( T val ) BOOST_NOEXCEPT { - boost::endian::endian_store( val, value_ ); + boost::endian::endian_store( value_, val ); } #endif endian_buffer& operator=( T val ) BOOST_NOEXCEPT { - boost::endian::endian_store( val, value_ ); + boost::endian::endian_store( value_, val ); return *this; } diff --git a/include/boost/endian/conversion.hpp b/include/boost/endian/conversion.hpp index f125a56..32ef5c5 100644 --- a/include/boost/endian/conversion.hpp +++ b/include/boost/endian/conversion.hpp @@ -9,6 +9,8 @@ #define BOOST_ENDIAN_CONVERSION_HPP #include +#include +#include #include #include #include diff --git a/include/boost/endian/detail/endian_store.hpp b/include/boost/endian/detail/endian_store.hpp index 42c4550..d8fa511 100644 --- a/include/boost/endian/detail/endian_store.hpp +++ b/include/boost/endian/detail/endian_store.hpp @@ -37,9 +37,9 @@ template -inline void endian_store( T const & v, unsigned char * p ) BOOST_NOEXCEPT +inline void endian_store( unsigned char * p, T const & v ) BOOST_NOEXCEPT { - return detail::endian_store_impl()( v, p ); + return detail::endian_store_impl()( p, v ); } namespace detail @@ -49,7 +49,7 @@ namespace detail template struct endian_store_impl { - inline void operator()( T const & v, unsigned char * p ) const BOOST_NOEXCEPT + inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT { BOOST_STATIC_ASSERT( is_trivially_copyable::value ); @@ -61,7 +61,7 @@ template struct endian_store template struct endian_store_impl { - inline void operator()( T const & v, unsigned char * p ) const BOOST_NOEXCEPT + inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT { BOOST_STATIC_ASSERT( is_trivially_copyable::value ); @@ -78,12 +78,12 @@ template struct endian_store_impl { - inline void operator()( T const & v, unsigned char * p ) const BOOST_NOEXCEPT + inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT { BOOST_STATIC_ASSERT( is_integral::value || is_enum::value ); unsigned char tmp[ 4 ]; - boost::endian::endian_store( v, tmp ); + boost::endian::endian_store( tmp, v ); p[0] = tmp[0]; p[1] = tmp[1]; @@ -93,12 +93,12 @@ template struct endian_store_impl struct endian_store_impl { - inline void operator()( T const & v, unsigned char * p ) const BOOST_NOEXCEPT + inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT { BOOST_STATIC_ASSERT( is_integral::value || is_enum::value ); unsigned char tmp[ 4 ]; - boost::endian::endian_store( v, tmp ); + boost::endian::endian_store( tmp, v ); p[0] = tmp[1]; p[1] = tmp[2]; @@ -110,12 +110,12 @@ template struct endian_store_impl struct endian_store_impl { - inline void operator()( T const & v, unsigned char * p ) const BOOST_NOEXCEPT + inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT { BOOST_STATIC_ASSERT( is_integral::value || is_enum::value ); unsigned char tmp[ 8 ]; - boost::endian::endian_store( v, tmp ); + boost::endian::endian_store( tmp, v ); p[0] = tmp[0]; p[1] = tmp[1]; @@ -127,12 +127,12 @@ template struct endian_store_impl struct endian_store_impl { - inline void operator()( T const & v, unsigned char * p ) const BOOST_NOEXCEPT + inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT { BOOST_STATIC_ASSERT( is_integral::value || is_enum::value ); unsigned char tmp[ 8 ]; - boost::endian::endian_store( v, tmp ); + boost::endian::endian_store( tmp, v ); p[0] = tmp[3]; p[1] = tmp[4]; @@ -146,12 +146,12 @@ template struct endian_store_impl struct endian_store_impl { - inline void operator()( T const & v, unsigned char * p ) const BOOST_NOEXCEPT + inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT { BOOST_STATIC_ASSERT( is_integral::value || is_enum::value ); unsigned char tmp[ 8 ]; - boost::endian::endian_store( v, tmp ); + boost::endian::endian_store( tmp, v ); p[0] = tmp[0]; p[1] = tmp[1]; @@ -164,12 +164,12 @@ template struct endian_store_impl struct endian_store_impl { - inline void operator()( T const & v, unsigned char * p ) const BOOST_NOEXCEPT + inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT { BOOST_STATIC_ASSERT( is_integral::value || is_enum::value ); unsigned char tmp[ 8 ]; - boost::endian::endian_store( v, tmp ); + boost::endian::endian_store( tmp, v ); p[0] = tmp[2]; p[1] = tmp[3]; @@ -184,12 +184,12 @@ template struct endian_store_impl struct endian_store_impl { - inline void operator()( T const & v, unsigned char * p ) const BOOST_NOEXCEPT + inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT { BOOST_STATIC_ASSERT( is_integral::value || is_enum::value ); unsigned char tmp[ 8 ]; - boost::endian::endian_store( v, tmp ); + boost::endian::endian_store( tmp, v ); p[0] = tmp[0]; p[1] = tmp[1]; @@ -203,12 +203,12 @@ template struct endian_store_impl struct endian_store_impl { - inline void operator()( T const & v, unsigned char * p ) const BOOST_NOEXCEPT + inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT { BOOST_STATIC_ASSERT( is_integral::value || is_enum::value ); unsigned char tmp[ 8 ]; - boost::endian::endian_store( v, tmp ); + boost::endian::endian_store( tmp, v ); p[0] = tmp[1]; p[1] = tmp[2]; diff --git a/test/endian_ld_st_roundtrip_test.cpp b/test/endian_ld_st_roundtrip_test.cpp index 163e09f..d64c38e 100644 --- a/test/endian_ld_st_roundtrip_test.cpp +++ b/test/endian_ld_st_roundtrip_test.cpp @@ -15,7 +15,7 @@ template void test( T const& x ) { unsigned char buffer[ sizeof(T) ]; - boost::endian::endian_store( x, buffer ); + boost::endian::endian_store( buffer, x ); T x2 = boost::endian::endian_load( buffer ); BOOST_TEST_EQ( x, x2 ); @@ -24,7 +24,7 @@ template void test( T const& x ) { unsigned char buffer[ sizeof(T) ]; - boost::endian::endian_store( x, buffer ); + boost::endian::endian_store( buffer, x ); T x2 = boost::endian::endian_load( buffer ); BOOST_TEST_EQ( x, x2 ); diff --git a/test/endian_store_test.cpp b/test/endian_store_test.cpp index 470a187..e3ce1d8 100644 --- a/test/endian_store_test.cpp +++ b/test/endian_store_test.cpp @@ -66,7 +66,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA }; - boost::endian::endian_store( 0x01, v ); + boost::endian::endian_store( v, 0x01 ); unsigned char w[] = { 0x01, 0xAA }; @@ -76,7 +76,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA }; - boost::endian::endian_store( 0x01, v ); + boost::endian::endian_store( v, 0x01 ); unsigned char w[] = { 0x01, 0xAA }; @@ -86,7 +86,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA }; - boost::endian::endian_store( 0x01, v ); + boost::endian::endian_store( v, 0x01 ); unsigned char w[] = { 0x01, 0xAA }; @@ -96,7 +96,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA }; - boost::endian::endian_store( 0x01, v ); + boost::endian::endian_store( v, 0x01 ); unsigned char w[] = { 0x01, 0xAA }; @@ -108,7 +108,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x0102, v ); + boost::endian::endian_store( v, 0x0102 ); unsigned char w[] = { 0x02, 0x01, 0xAA }; @@ -118,7 +118,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x0102, v ); + boost::endian::endian_store( v, 0x0102 ); unsigned char w[] = { 0x02, 0x01, 0xAA }; @@ -128,7 +128,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x0102, v ); + boost::endian::endian_store( v, 0x0102 ); unsigned char w[] = { 0x01, 0x02, 0xAA }; @@ -138,7 +138,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x0102, v ); + boost::endian::endian_store( v, 0x0102 ); unsigned char w[] = { 0x01, 0x02, 0xAA }; @@ -150,7 +150,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x010203, v ); + boost::endian::endian_store( v, 0x010203 ); unsigned char w[] = { 0x03, 0x02, 0x01, 0xAA }; @@ -160,7 +160,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x010203, v ); + boost::endian::endian_store( v, 0x010203 ); unsigned char w[] = { 0x03, 0x02, 0x01, 0xAA }; @@ -170,7 +170,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x010203, v ); + boost::endian::endian_store( v, 0x010203 ); unsigned char w[] = { 0x01, 0x02, 0x03, 0xAA }; @@ -180,7 +180,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x010203, v ); + boost::endian::endian_store( v, 0x010203 ); unsigned char w[] = { 0x01, 0x02, 0x03, 0xAA }; @@ -192,7 +192,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x01020304, v ); + boost::endian::endian_store( v, 0x01020304 ); unsigned char w[] = { 0x04, 0x03, 0x02, 0x01, 0xAA }; @@ -202,7 +202,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x01020304, v ); + boost::endian::endian_store( v, 0x01020304 ); unsigned char w[] = { 0x04, 0x03, 0x02, 0x01, 0xAA }; @@ -212,7 +212,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x01020304, v ); + boost::endian::endian_store( v, 0x01020304 ); unsigned char w[] = { 0x01, 0x02, 0x03, 0x04, 0xAA }; @@ -222,7 +222,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x01020304, v ); + boost::endian::endian_store( v, 0x01020304 ); unsigned char w[] = { 0x01, 0x02, 0x03, 0x04, 0xAA }; @@ -234,7 +234,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x0102030405, v ); + boost::endian::endian_store( v, 0x0102030405 ); unsigned char w[] = { 0x05, 0x04, 0x03, 0x02, 0x01, 0xAA }; @@ -244,7 +244,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x0102030405, v ); + boost::endian::endian_store( v, 0x0102030405 ); unsigned char w[] = { 0x05, 0x04, 0x03, 0x02, 0x01, 0xAA }; @@ -254,7 +254,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x0102030405, v ); + boost::endian::endian_store( v, 0x0102030405 ); unsigned char w[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0xAA }; @@ -264,7 +264,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x0102030405, v ); + boost::endian::endian_store( v, 0x0102030405 ); unsigned char w[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0xAA }; @@ -276,7 +276,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x010203040506, v ); + boost::endian::endian_store( v, 0x010203040506 ); unsigned char w[] = { 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0xAA }; @@ -286,7 +286,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x010203040506, v ); + boost::endian::endian_store( v, 0x010203040506 ); unsigned char w[] = { 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0xAA }; @@ -296,7 +296,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x010203040506, v ); + boost::endian::endian_store( v, 0x010203040506 ); unsigned char w[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0xAA }; @@ -306,7 +306,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x010203040506, v ); + boost::endian::endian_store( v, 0x010203040506 ); unsigned char w[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0xAA }; @@ -318,7 +318,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x01020304050607, v ); + boost::endian::endian_store( v, 0x01020304050607 ); unsigned char w[] = { 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0xAA }; @@ -328,7 +328,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x01020304050607, v ); + boost::endian::endian_store( v, 0x01020304050607 ); unsigned char w[] = { 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0xAA }; @@ -338,7 +338,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x01020304050607, v ); + boost::endian::endian_store( v, 0x01020304050607 ); unsigned char w[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0xAA }; @@ -348,7 +348,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x01020304050607, v ); + boost::endian::endian_store( v, 0x01020304050607 ); unsigned char w[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0xAA }; @@ -360,7 +360,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x0102030405060708, v ); + boost::endian::endian_store( v, 0x0102030405060708 ); unsigned char w[] = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0xAA }; @@ -370,7 +370,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x0102030405060708, v ); + boost::endian::endian_store( v, 0x0102030405060708 ); unsigned char w[] = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0xAA }; @@ -380,7 +380,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x0102030405060708, v ); + boost::endian::endian_store( v, 0x0102030405060708 ); unsigned char w[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0xAA }; @@ -390,7 +390,7 @@ int main() { unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; - boost::endian::endian_store( 0x0102030405060708, v ); + boost::endian::endian_store( v, 0x0102030405060708 ); unsigned char w[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0xAA };