diff -uNr orig/endian-0.5/boost/integer/cover_operators.hpp endian-0.5/boost/integer/cover_operators.hpp --- orig/endian-0.5/boost/integer/cover_operators.hpp 2006-06-18 21:09:00.000000000 -0500 +++ endian-0.5/boost/integer/cover_operators.hpp 2006-07-20 15:19:49.000000000 -0500 @@ -37,16 +37,16 @@ friend bool operator<(const T& x, IntegerType y) { return +x < y; } // The basic arithmetic operations. - friend T& operator+=(T& x, IntegerType y) { return x = +x + y; } - friend T& operator-=(T& x, IntegerType y) { return x = +x - y; } - friend T& operator*=(T& x, IntegerType y) { return x = +x * y; } - friend T& operator/=(T& x, IntegerType y) { return x = +x / y; } - friend T& operator%=(T& x, IntegerType y) { return x = +x % y; } - friend T& operator&=(T& x, IntegerType y) { return x = +x & y; } - friend T& operator|=(T& x, IntegerType y) { return x = +x | y; } - friend T& operator^=(T& x, IntegerType y) { return x = +x ^ y; } - friend T& operator<<=(T& x, IntegerType y) { return x = +x << y; } - friend T& operator>>=(T& x, IntegerType y) { return x = +x >> y; } + friend T& operator+=(T& x, IntegerType y) { x = +x + y; return x; } + friend T& operator-=(T& x, IntegerType y) { x = +x - y; return x; } + friend T& operator*=(T& x, IntegerType y) { x = +x * y; return x; } + friend T& operator/=(T& x, IntegerType y) { x = +x / y; return x; } + friend T& operator%=(T& x, IntegerType y) { x = +x % y; return x; } + friend T& operator&=(T& x, IntegerType y) { x = +x & y; return x; } + friend T& operator|=(T& x, IntegerType y) { x = +x | y; return x; } + friend T& operator^=(T& x, IntegerType y) { x = +x ^ y; return x; } + friend T& operator<<=(T& x, IntegerType y) { x = +x << y; return x; } + friend T& operator>>=(T& x, IntegerType y) { x = +x >> y; return x; } // A few binary arithmetic operations not covered by operators base class. friend IntegerType operator<<(const T& x, IntegerType y) { return +x << y; } @@ -54,8 +54,8 @@ // Auto-increment and auto-decrement can be defined in terms of the // arithmetic operations. - friend T& operator++(T& x) { return x += 1; } - friend T& operator--(T& x) { return x -= 1; } + friend T& operator++(T& x) { x += 1; return x; } + friend T& operator--(T& x) { x -= 1; return x; } /// TODO: stream I/O needs to be templatized on the stream type, so will /// work with wide streams, etc. diff -uNr orig/endian-0.5/boost/integer/endian.hpp endian-0.5/boost/integer/endian.hpp --- orig/endian-0.5/boost/integer/endian.hpp 2006-06-22 07:27:42.000000000 -0500 +++ endian-0.5/boost/integer/endian.hpp 2006-07-20 15:21:03.000000000 -0500 @@ -145,10 +145,12 @@ { public: typedef T value_type; - endian() {} - endian(T i) { detail::store_big_endian(bytes, i); } + static endian init(T i) { endian e; e = i; return e; } + void operator=(T i) { detail::store_big_endian(bytes, i); } operator T() const { return detail::load_big_endian(bytes); } + T operator()() const + { return detail::load_big_endian(bytes); } private: char bytes[n_bytes]; }; @@ -159,8 +161,8 @@ { public: typedef T value_type; - endian() {} - endian(T i) { detail::store_little_endian(bytes, i); } + static endian init(T i) { endian e; e = i; return e; } + void operator=(T i) { detail::store_little_endian(bytes, i); } operator T() const { return detail::load_little_endian(bytes); } private: @@ -173,13 +175,13 @@ { public: typedef T value_type; - endian() {} + static endian init(T i) { endian e; e = i; return e; } # ifdef BOOST_BIG_ENDIAN - endian(T i) { detail::store_big_endian(bytes, i); } + void operator=(T i) { detail::store_big_endian(bytes, i); } operator T() const { return detail::load_big_endian(bytes); } # else - endian(T i) { detail::store_little_endian(bytes, i); } + void operator=(T i) { detail::store_little_endian(bytes, i); } operator T() const { return detail::load_little_endian(bytes); } # endif @@ -197,12 +199,12 @@ public: BOOST_STATIC_ASSERT( sizeof(T) == n_bytes ); typedef T value_type; - endian() {} + static endian init(T i) { endian e; e = i; return e; } #ifdef BOOST_BIG_ENDIAN - endian(T i) : integer(i) { } + void operator=(T i) { integer = i; } operator T() const { return integer; } #else - endian(T i) { detail::store_big_endian(&integer, i); } + void operator=(T i) { detail::store_big_endian(&integer, i); } operator T() const { return detail::load_big_endian(&integer); } #endif @@ -217,13 +219,12 @@ public: BOOST_STATIC_ASSERT( sizeof(T) == n_bytes ); typedef T value_type; - endian() {} + static endian init(T i) { endian e; e = i; return e; } #ifdef BOOST_LITTLE_ENDIAN - endian(T i) : integer(i) { } + void operator=(T i) { integer = i; } operator T() const { return integer; } #else - endian(T i) - { detail::store_little_endian(&integer, i); } + void operator=(T i) { detail::store_little_endian(&integer, i); } operator T() const { return detail::load_little_endian(&integer); } #endif diff -uNr orig/endian-0.5/libs/integer/test/endian_test.cpp endian-0.5/libs/integer/test/endian_test.cpp --- orig/endian-0.5/libs/integer/test/endian_test.cpp 2006-06-19 08:44:50.000000000 -0500 +++ endian-0.5/libs/integer/test/endian_test.cpp 2006-07-20 15:24:48.000000000 -0500 @@ -54,7 +54,7 @@ template void verify_value_and_ops( const Base & expected, int line ) { - Endian v( expected ); + Endian v = Endian::init( expected ); verify( v == expected, line ); ++v; // verify integer_cover_operators being applied to this type - @@ -68,8 +68,8 @@ void verify_representation( bool is_big, int line ) { int silence = 0; - Endian x = static_cast - (0x123456789abcdef0LL + silence); // will truncate + Endian x = Endian::init(static_cast + (0x123456789abcdef0LL + silence)); // will truncate if ( is_big ) verify( memcmp( &x, @@ -323,6 +323,108 @@ } } // check_alignment + // check_unions -----------------------------------------------------------// + + void check_unions() + { + union union1 + { + big1_t v0; + ubig1_t v1; + little1_t v2; + ulittle1_t v3; + native1_t v4; + unative1_t v5; + }; + + union union2 + { + big2_t v0; + ubig2_t v1; + little2_t v2; + ulittle2_t v3; + native2_t v4; + unative2_t v5; + }; + + union union3 + { + big3_t v0; + ubig3_t v1; + little3_t v2; + ulittle3_t v3; + native3_t v4; + unative3_t v5; + }; + + union union4 + { + big4_t v0; + ubig4_t v1; + little4_t v2; + ulittle4_t v3; + native4_t v4; + unative4_t v5; + }; + + union union5 + { + big5_t v0; + ubig5_t v1; + little5_t v2; + ulittle5_t v3; + native5_t v4; + unative5_t v5; + }; + + union union6 + { + big6_t v0; + ubig6_t v1; + little6_t v2; + ulittle6_t v3; + native6_t v4; + unative6_t v5; + }; + + union union7 + { + big7_t v0; + ubig7_t v1; + little7_t v2; + ulittle7_t v3; + native7_t v4; + unative7_t v5; + }; + + union union8 + { + big8_t v0; + ubig8_t v1; + little8_t v2; + ulittle8_t v3; + native8_t v4; + unative8_t v5; + }; + + int saved_err_count = err_count; + + VERIFY_SIZE( sizeof(union1), 1 ); + VERIFY_SIZE( sizeof(union2), 2 ); + VERIFY_SIZE( sizeof(union3), 3 ); + VERIFY_SIZE( sizeof(union4), 4 ); + VERIFY_SIZE( sizeof(union5), 5 ); + VERIFY_SIZE( sizeof(union6), 6 ); + VERIFY_SIZE( sizeof(union7), 7 ); + VERIFY_SIZE( sizeof(union8), 8 ); + + if ( saved_err_count == err_count ) + { + cout << + "Size for unions of endian types are as expected.\n"; + } + } // chedck_unions + // check_representation_and_range_and_ops --------------------------------// void check_representation_and_range_and_ops() @@ -575,6 +677,7 @@ detect_endianness(); check_size(); check_alignment(); + check_unions(); check_representation_and_range_and_ops(); //timing_test ( "big4_t" );