From 1218fc6f5ce8c3cc1eb73ff71835efa59b5d50ee Mon Sep 17 00:00:00 2001 From: bemandawes Date: Sun, 15 Mar 2009 14:41:41 +0000 Subject: [PATCH] Endian: endian_hello_world tweaks git-svn-id: http://svn.boost.org/svn/boost/sandbox/endian@51785 b8fc166d-592f-0410-95f2-cb63ce0dd405 --- boost/integer/cover_operators.hpp | 10 +++++----- libs/integer/example/endian_hello_world.cpp | 13 +++++-------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/boost/integer/cover_operators.hpp b/boost/integer/cover_operators.hpp index 56cf3c8..4b970cd 100644 --- a/boost/integer/cover_operators.hpp +++ b/boost/integer/cover_operators.hpp @@ -65,16 +65,16 @@ namespace boost friend T& operator<<=(T& x, IntegerType y) { return x = +x << y; } friend T& operator>>=(T& x, IntegerType y) { return x = +x >> y; } - // A few binary arithmetic operations not covered by operators base class. - friend IntegerType operator<<(const T& x, IntegerType y) { return +x << y; } - friend IntegerType operator>>(const T& x, IntegerType y) { return +x >> y; } - // 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; } -# ifdef BOOST_MINIMAL_INTEGER_COVER_OPERATORS +# ifndef BOOST_MINIMAL_INTEGER_COVER_OPERATORS + // A few binary arithmetic operations not covered by operators base class. + friend IntegerType operator<<(const T& x, IntegerType y) { return +x << y; } + friend IntegerType operator>>(const T& x, IntegerType y) { return +x >> y; } + friend T operator++(T& x, int) { T tmp(x); diff --git a/libs/integer/example/endian_hello_world.cpp b/libs/integer/example/endian_hello_world.cpp index 8356471..a8a1a8d 100644 --- a/libs/integer/example/endian_hello_world.cpp +++ b/libs/integer/example/endian_hello_world.cpp @@ -9,6 +9,7 @@ #include #include +#include #include using namespace boost; @@ -16,14 +17,10 @@ using namespace boost::integer; int main() { - int_least32_t value = 0x313233L; // = 3224115 = ASCII { '1', '2', '3' } - big24_t big( value ); - little24_t little( value ); - + int_least32_t v = 0x31323334L; // = ASCII { '1', '2', '3', '4' } + // value chosen to work on text stream std::cout << "Hello, endian world!\n"; - std::cout << " cout << value--: " << value << " sizeof(value): " << sizeof(value) - << "\n cout << big----: " << big << " sizeof(big): " << sizeof(big) - << "\n cout << little-: " << little << " sizeof(little): " << sizeof(little) - << '\n'; + std::cout << v << " " << big32_t(v) << " " << little32_t(v) << '\n'; + std::cout <= v <= ' ' <= big32_t(v) <= ' ' <= little32_t(v) <= '\n'; }