From 2fcc1b30c7a284dd134ffaa875abc6283dc4fee8 Mon Sep 17 00:00:00 2001 From: Davis King Date: Sat, 28 May 2011 17:19:20 -0400 Subject: [PATCH] Changed code to use the new DLIB_ASSERT_HAS_STANDARD_LAYOUT to check if a type can be swapped rather than the explicit union trick. --- dlib/byte_orderer/byte_orderer_kernel_1.h | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/dlib/byte_orderer/byte_orderer_kernel_1.h b/dlib/byte_orderer/byte_orderer_kernel_1.h index 1f15ca16c..e588a6b4a 100644 --- a/dlib/byte_orderer/byte_orderer_kernel_1.h +++ b/dlib/byte_orderer/byte_orderer_kernel_1.h @@ -136,14 +136,9 @@ namespace dlib - reverses the byte ordering in item !*/ { - // this is just here to provide a compile time check that T is a POD. - // this checks *most* of the requirements for being a POD type. - // You should not be calling this function on non POD types! - union - { - int a; - T value; - } temp; + DLIB_ASSERT_HAS_STANDARD_LAYOUT(T); + + T value; // If you are getting this as an error then you are probably using // this object wrong. If you think you aren't then send me (Davis) an @@ -161,11 +156,11 @@ namespace dlib const size_t size = sizeof(T); unsigned char* const ptr = reinterpret_cast(&item); - unsigned char* const ptr_temp = reinterpret_cast(&temp.value); + unsigned char* const ptr_temp = reinterpret_cast(&value); for (size_t i = 0; i < size; ++i) ptr_temp[size-i-1] = ptr[i]; - item = temp.value; + item = value; } bool little_endian;