From 11fc1ea37485d9aa190effa922764c3d63860a8a Mon Sep 17 00:00:00 2001 From: Pierre Talbot Date: Wed, 22 Jan 2014 18:09:50 +0100 Subject: [PATCH] Add overloads for int8_t and uint8_t (rational: useful with generic programming). Template the reverse function (same body in each overloads). --- include/boost/endian/conversion.hpp | 32 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/include/boost/endian/conversion.hpp b/include/boost/endian/conversion.hpp index f2a8175..b1fb702 100644 --- a/include/boost/endian/conversion.hpp +++ b/include/boost/endian/conversion.hpp @@ -35,9 +35,11 @@ namespace endian // reverse byte order (i.e. endianness) // + inline int8_t reverse_value(int8_t x) BOOST_NOEXCEPT; inline int16_t reverse_value(int16_t x) BOOST_NOEXCEPT; inline int32_t reverse_value(int32_t x) BOOST_NOEXCEPT; inline int64_t reverse_value(int64_t x) BOOST_NOEXCEPT; + inline uint8_t reverse_value(uint8_t x) BOOST_NOEXCEPT; inline uint16_t reverse_value(uint16_t x) BOOST_NOEXCEPT; inline uint32_t reverse_value(uint32_t x) BOOST_NOEXCEPT; inline uint64_t reverse_value(uint64_t x) BOOST_NOEXCEPT; @@ -87,14 +89,8 @@ namespace endian // reverse byte order (i.e. endianness) // - inline void reverse(int16_t& x) BOOST_NOEXCEPT; - inline void reverse(int32_t& x) BOOST_NOEXCEPT; - inline void reverse(int64_t& x) BOOST_NOEXCEPT; - inline void reverse(uint16_t& x) BOOST_NOEXCEPT; - inline void reverse(uint32_t& x) BOOST_NOEXCEPT; - inline void reverse(uint64_t& x) BOOST_NOEXCEPT; - inline void reverse(float& x) BOOST_NOEXCEPT; - inline void reverse(double& x) BOOST_NOEXCEPT; + template + inline void reverse(Value& x) BOOST_NOEXCEPT; // reverse unless native endianness is big template @@ -157,6 +153,11 @@ namespace endian // who provided his Boost licensed macro implementation (detail/intrinsic.hpp) // // // //--------------------------------------------------------------------------------------// + + inline int8_t reverse_value(int8_t x) BOOST_NOEXCEPT + { + return x; + } inline int16_t reverse_value(int16_t x) BOOST_NOEXCEPT { @@ -194,6 +195,11 @@ namespace endian return BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_8(static_cast(x)); # endif } + + inline uint8_t reverse_value(uint8_t x) BOOST_NOEXCEPT + { + return x; + } inline uint16_t reverse_value(uint16_t x) BOOST_NOEXCEPT { @@ -379,14 +385,8 @@ namespace endian // reverse byte order (i.e. endianness) // - inline void reverse(int16_t& x) BOOST_NOEXCEPT {x = reverse_value(x);} - inline void reverse(int32_t& x) BOOST_NOEXCEPT {x = reverse_value(x);} - inline void reverse(int64_t& x) BOOST_NOEXCEPT {x = reverse_value(x);} - inline void reverse(uint16_t& x) BOOST_NOEXCEPT {x = reverse_value(x);} - inline void reverse(uint32_t& x) BOOST_NOEXCEPT {x = reverse_value(x);} - inline void reverse(uint64_t& x) BOOST_NOEXCEPT {x = reverse_value(x);} - inline void reverse(float& x) BOOST_NOEXCEPT {x = reverse_value(x);} - inline void reverse(double& x) BOOST_NOEXCEPT {x = reverse_value(x);} + template + inline void reverse(Value& x) BOOST_NOEXCEPT {x = reverse_value(x);} // reverse unless native endianness is big template