From 84ad1a041feeee66e7c5e6484d706618bf4fb49c Mon Sep 17 00:00:00 2001
From: Beman The The template definitions in this header refer to named
requirements whose details are set out in this section. User defined types may
@@ -203,9 +207,11 @@ udt_conversion_example.cpp for an example of a UDT that can used in the
little_endian, and Returns: Postconditions: The order of the constituent bytes of
implementation-defined
text above is either
+big
or little
according to the endianness of the
+platform.Requirements
convert
function templates.Functions
-int16_t reverse_value(int16_t x) noexcept;
+
int8_t reverse_value(int8_t x) noexcept;
+int16_t reverse_value(int16_t x) noexcept;
int32_t reverse_value(int32_t x) noexcept;
int64_t reverse_value(int64_t x) noexcept;
+uint8_t reverse_value(uint8_t x) noexcept;
uint16_t reverse_value(uint16_t x) noexcept;
uint32_t reverse_value(uint32_t x) noexcept;
uint64_t reverse_value(uint64_t x) noexcept;
@@ -215,14 +221,8 @@ double reverse_value(double x) noexcept;
x
, with the order of its
constituent bytes reversed.void reverse(int16_t& x) noexcept;
-void reverse(int32_t& x) noexcept;
-void reverse(int64_t& x) noexcept;
-void reverse(uint16_t& x) noexcept;
-void reverse(uint32_t& x) noexcept;
-void reverse(uint64_t& x) noexcept;
-void reverse(float& x) noexcept;
-void reverse(double& x) noexcept;
+template <class Value>
+ void reverse(Value& x) noexcept;
x
are reversed.
Tomas Puverle was instrumental in identifying and articulating the need to -support endian conversion as separate from endian integer types. Phil Endecott suggested the form of the value returning signatures. Vicente Botet and other reviewers suggested supporting floating point types and user defined types. General reverse template implementation approach using std::reverse suggested by Mathias Gaunard. Portable implementation approach for 16, 32, and 64-bit integers suggested by tymofey, with avoidance of undefined behavior as suggested by Giovanni Piero Deretta, and a further refinement suggested by Pyry Jahkola. Intrinsic builtins implementation approach for 16, 32, and 64-bit integers suggested by several reviewers, and by David Stone, who provided his Boost licensed macro implementation that became the starting point for boost/endian/detail/intrinsic.hpp.
+support endian conversion as separate from endian integer types. Phil Endecott suggested the form of the value returning signatures. Vicente Botet and other reviewers suggested supporting floating point types and user defined types. General reverse template implementation approach using std::reverse suggested by Mathias Gaunard. Portable implementation approach for 16, 32, and 64-bit integers suggested by tymofey, with avoidance of undefined behavior as suggested by Giovanni Piero Deretta, and a further refinement suggested by Pyry Jahkola. Intrinsic builtins implementation approach for 16, 32, and 64-bit integers suggested by several reviewers, and by David Stone, who provided his Boost licensed macro implementation that became the starting point for boost/endian/detail/intrinsic.hpp. +Pierre Talbot provided theint8_t reverse_value()
and templated
+reverse()
implementations.
Last revised: -29 May, 2013
+12 August, 2014© Copyright Beman Dawes, 2011, 2013
Distributed under the Boost Software License, Version 1.0. See www.boost.org/ LICENSE_1_0.txt
diff --git a/index.html b/index.html index 7b7f0b5..6c6f3c4 100644 --- a/index.html +++ b/index.html @@ -46,7 +46,7 @@ Introduction to endiannessHeads up: As development has continues, there have been breaking - changes. Most recently, the endian types were - renamed. | -
Boost.Endian provides facilities to manipulate the endianness of integers, floating point, and user defined data.
A need to simplify program logic and eliminate logic
errors. Since the endian types mimic the built-in types, there is no need to reason about the current endianness of variables
- and that can simplify program logic and eliminate logic errors.
-
A need to use unusual integer sizes (i.e. 3, 5,
6, or 7 bytes) to reduce internal and external space usage and
- save I/O time.
-
A need to use unaligned variables. Endian types can eliminate padding bytes in structures, reducing internal and external space usage and saving I/O - time. They can deals with structures defined like this:
+ } __attribute__ ((packed)); + +-
struct S {
uint16_t a;
uint32_t b;
- } __attribute__ ((packed));
Programmer preference.
A need to leverage knowledge of developers who have been using C byte
swapping
- functions for years.
-
A need to pass structures to third-party libraries expecting a + specific structure format.
Programmer preference.
Recent compilers, including GCC, Clang, and Microsoft, supply intrinsic -built-in support for byte swapping. Such support is automatically detected and +
Recent compilers, including GCC, Clang, and Microsoft, supply built-in support for byte swapping +intrinsics. Such support is automatically detected and used since it may in smaller and faster generated code, particularly for release builds.
-Defining BOOST_ENDIAN_NO_INTRINSICS
will suppress use
+
Defining BOOST_ENDIAN_NO_INTRINSICS
will suppress use
of the intrinsics. Please try defining it if you get compiler errors, such as
header byteswap.h not being found.
The macro BOOST_ENDIAN_INTRINSIC_MSG
is defined as
+
The macro BOOST_ENDIAN_INTRINSIC_MSG
is defined as
either "no byte swap intrinsics"
or a string describing the
particular set of intrinsics being used.
There will be no performance difference between the two approaches, -regardless of the native endianness of the machine. Optimizing compilers will likely -generate exactly the same code for both. That conclusion was confirmed by +
There will be no performance difference between the two approaches in +release builds, +regardless of the native endianness of the machine. That's because optimizing compilers will likely +generate exactly the same code for each. That conclusion was confirmed by studying the generated assembly code for GCC and Visual C++.
Now consider a slightly different problem:
@@ -337,84 +331,180 @@ setup. 32-bit intrinsics.)GNU C++ version 4.7.0 | |||||
Iterations: 1000000000, Intrinsics: __builtin_bswap16, etc. | |||||
Test Case | -Endian type |
-Endian conversion function |
+|||
GNU C++ version 4.7.0 | |||||
Iterations: 1000000000, Intrinsics: __builtin_bswap16, etc. | |||||
Test Case | +Endian type |
+Endian conversion function |
|||
16-bit aligned big endian | 1.37 s | 0.81 s | |||
16-bit aligned little endian | 0.83 s | 0.81 s | |||
16-bit unaligned big endian | 1.09 s | 0.83 s | |||
16-bit unaligned little endian | 1.09 s | 0.81 s | |||
32-bit aligned big endian | 0.98 s | 0.27 s | |||
32-bit aligned little endian | 0.28 s | 0.27 s | |||
32-bit unaligned big endian | 3.82 s | 0.27 s | |||
32-bit unaligned little endian | 3.82 s | 0.27 s | |||
64-bit aligned big endian | 1.65 s | 0.41 s | |||
64-bit aligned little endian | 0.41 s | 0.41 s | |||
64-bit unaligned big endian | 17.53 s | 0.41 s | |||
64-bit unaligned little endian | 17.52 s | 0.41 s | |||
16-bit aligned big endian | +1.37 s | +0.81 s | |||
16-bit aligned little endian | +0.83 s | +0.81 s | |||
16-bit unaligned big endian | +1.09 s | +0.83 s | |||
16-bit unaligned little endian | +1.09 s | +0.81 s | |||
32-bit aligned big endian | +0.98 s | +0.27 s | |||
32-bit aligned little endian | +0.28 s | +0.27 s | |||
32-bit unaligned big endian | +3.82 s | +0.27 s | |||
32-bit unaligned little endian | +3.82 s | +0.27 s | |||
64-bit aligned big endian | +1.65 s | +0.41 s | |||
64-bit aligned little endian | +0.41 s | +0.41 s | |||
64-bit unaligned big endian | +17.53 s | +0.41 s | |||
64-bit unaligned little endian | +17.52 s | +0.41 s | |||
Iterations: 1000000000, Intrinsics: no byte swap intrinsics | |||||
Test Case | -Endian type |
-Endian conversion function |
+|||
Iterations: 1000000000, Intrinsics: no byte swap intrinsics | |||||
Test Case | +Endian type |
+Endian conversion function |
|||
16-bit aligned big endian | 1.95 s | 0.81 s | |||
16-bit aligned little endian | 0.83 s | 0.81 s | |||
16-bit unaligned big endian | 1.19 s | 0.81 s | |||
16-bit unaligned little endian | 1.20 s | 0.81 s | |||
32-bit aligned big endian | 0.97 s | 0.28 s | |||
32-bit aligned little endian | 0.27 s | 0.28 s | |||
32-bit unaligned big endian | 4.10 s | 0.27 s | |||
32-bit unaligned little endian | 4.10 s | 0.27 s | |||
64-bit aligned big endian | 1.64 s | 0.42 s | |||
64-bit aligned little endian | 0.41 s | 0.41 s | |||
64-bit unaligned big endian | 17.52 s | 0.42 s | |||
64-bit unaligned little endian | 17.52 s | 0.41 s | |||
16-bit aligned big endian | +1.95 s | +0.81 s | |||
16-bit aligned little endian | +0.83 s | +0.81 s | |||
16-bit unaligned big endian | +1.19 s | +0.81 s | |||
16-bit unaligned little endian | +1.20 s | +0.81 s | |||
32-bit aligned big endian | +0.97 s | +0.28 s | |||
32-bit aligned little endian | +0.27 s | +0.28 s | |||
32-bit unaligned big endian | +4.10 s | +0.27 s | |||
32-bit unaligned little endian | +4.10 s | +0.27 s | |||
64-bit aligned big endian | +1.64 s | +0.42 s | |||
64-bit aligned little endian | +0.41 s | +0.41 s | |||
64-bit unaligned big endian | +17.52 s | +0.42 s | |||
64-bit unaligned little endian | +17.52 s | +0.41 s |
Microsoft Visual C++ version 11.0 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Iterations: 1000000000, Intrinsics: cstdlib _byteswap_ushort, etc. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Test Case | -Endian type |
-Endian conversion function |
+
Microsoft Visual C++ version 11.0 | |||||
Iterations: 1000000000, Intrinsics: cstdlib _byteswap_ushort, etc. | |||||
Test Case | +Endian type |
+Endian conversion function |
|||
16-bit aligned big endian | 0.83 s | 0.51 s | |||
16-bit aligned little endian | 0.51 s | 0.50 s | |||
16-bit unaligned big endian | 1.37 s | 0.51 s | |||
16-bit unaligned little endian | 1.37 s | 0.50 s | |||
32-bit aligned big endian | 0.81 s | 0.50 s | |||
32-bit aligned little endian | 0.51 s | 0.51 s | |||
32-bit unaligned big endian | 2.98 s | 0.53 s | |||
32-bit unaligned little endian | 3.00 s | 0.51 s | |||
64-bit aligned big endian | 1.33 s | 0.33 s | |||
64-bit aligned little endian | 0.34 s | 0.27 s | |||
64-bit unaligned big endian | 7.05 s | 0.33 s | |||
64-bit unaligned little endian | 7.11 s | 0.31 s | |||
16-bit aligned big endian | +0.83 s | +0.51 s | |||
16-bit aligned little endian | +0.51 s | +0.50 s | |||
16-bit unaligned big endian | +1.37 s | +0.51 s | |||
16-bit unaligned little endian | +1.37 s | +0.50 s | |||
32-bit aligned big endian | +0.81 s | +0.50 s | |||
32-bit aligned little endian | +0.51 s | +0.51 s | |||
32-bit unaligned big endian | +2.98 s | +0.53 s | |||
32-bit unaligned little endian | +3.00 s | +0.51 s | |||
64-bit aligned big endian | +1.33 s | +0.33 s | |||
64-bit aligned little endian | +0.34 s | +0.27 s | |||
64-bit unaligned big endian | +7.05 s | +0.33 s | |||
64-bit unaligned little endian | +7.11 s | +0.31 s | |||
Iterations: 1000000000, Intrinsics: no byte swap intrinsics | |||||
Test Case | -Endian type |
-Endian conversion function |
+|||
Iterations: 1000000000, Intrinsics: no byte swap intrinsics | |||||
Test Case | +Endian type |
+Endian conversion function |
|||
16-bit aligned big endian | 0.83 s | 0.51 s | |||
16-bit aligned little endian | 0.51 s | 0.51 s | |||
16-bit unaligned big endian | 1.36 s | 0.51 s | |||
16-bit unaligned little endian | 1.37 s | 0.51 s | |||
32-bit aligned big endian | 3.42 s | 0.50 s | |||
32-bit aligned little endian | 0.51 s | 0.51 s | |||
32-bit unaligned big endian | 2.93 s | 0.50 s | |||
32-bit unaligned little endian | 2.95 s | 0.50 s | |||
64-bit aligned big endian | 5.99 s | 0.33 s | |||
64-bit aligned little endian | 0.33 s | 0.33 s | |||
64-bit unaligned big endian | 7.02 s | 0.27 s | |||
64-bit unaligned little endian | 7.02 s | 0.27 s | |||
16-bit aligned big endian | +0.83 s | +0.51 s | |||
16-bit aligned little endian | +0.51 s | +0.51 s | |||
16-bit unaligned big endian | +1.36 s | +0.51 s | |||
16-bit unaligned little endian | +1.37 s | +0.51 s | |||
32-bit aligned big endian | +3.42 s | +0.50 s | |||
32-bit aligned little endian | +0.51 s | +0.51 s | |||
32-bit unaligned big endian | +2.93 s | +0.50 s | |||
32-bit unaligned little endian | +2.95 s | +0.50 s | |||
64-bit aligned big endian | +5.99 s | +0.33 s | |||
64-bit aligned little endian | +0.33 s | +0.33 s | |||
64-bit unaligned big endian | +7.02 s | +0.27 s | |||
64-bit unaligned little endian | +7.02 s | +0.27 s |
Which is better, big-endian or little-endian?
-@@ -498,7 +588,7 @@ gives more pros and cons.Big-endian tends to be a -bit more of an industry standard, but little-endian may be preferred for -applications that run primarily Intel/AMD on x86, x64, and other little-endian +
Big-endian tends to be preferred in a networking environment and is a bit +more of an industry standard, but little-endian may be preferred for +applications that run primarily on x86, x64, and other little-endian CPU's. The Wikipedia article gives more pros and cons.
These are the only endian schemes that have any practical value today. PDP-11 and the other middle endian approaches are interesting historical curiosities -but have no relevance to C++ developers.
+but have no relevance to today's C++ developers.
What are the limitations of floating point support?
@@ -534,16 +624,14 @@ and 16, 32, and 64-bit aligned integers. 64-bit(double)
floating point, as requested.
order::native
is now a synonym for order::big
+ or order::little
according to the endianness of the platform, as
+ requested. This reduces the number of template specializations required.reverse_value()
overloads for int8_t
and
+ uint8_t
have been added for improved generality. (Pierre Talbot)reverse()
have been replaced with a single
+ reverse()
template. (Pierre Talbot)noexcept
are now used, while still
supporting C++03 compilers.Comments and suggestions were -received from -Adder, Benaka Moorthi, -Christopher Kohlhoff, -Cliff Green, Daniel James, Gennaro Proto, -Giovanni Piero Deretta, Gordon Woodhull, dizzy, Hartmut Kaiser, Jeff Flinn, -John Filo, John Maddock, -Kim Barrett, -Marsh Ray, -Martin Bonner, Mathias Gaunard, Matias Capeletto, -Neil Mayhew, Paul Bristow, Phil Endecott, Pyry Jahkola, Rene Rivera, -Robert Stewart, Roland Schwarz, Scott McMurray, -Sebastian Redl, -Tim Blechmann, Tim Moore, tymofey, Tomas Puverle, Vincente Botet, Yuval Ronen -and Vitaly Budovski,.
+Comments and suggestions were received from Adder, Benaka Moorthi, +Christopher Kohlhoff, Cliff Green, Daniel James, Gennaro Proto, Giovanni Piero +Deretta, Gordon Woodhull, dizzy, Hartmut Kaiser, Jeff Flinn, John Filo, John +Maddock, Kim Barrett, Marsh Ray, Martin Bonner, Mathias Gaunard, Matias +Capeletto, Neil Mayhew, Paul Bristow, Pierre Talbot, Phil Endecott, Pyry Jahkola, +Rene Rivera, Robert Stewart, Roland Schwarz, Scott McMurray, Sebastian Redl, Tim +Blechmann, Tim Moore, tymofey, Tomas Puverle, Vincente Botet, Yuval Ronen and +Vitaly Budovski,.
Last revised: -01 September, 2013
+12 August, 2014© Copyright Beman Dawes, 2011, 2013
Distributed under the Boost Software License, Version 1.0. See www.boost.org/ LICENSE_1_0.txt
diff --git a/types.html b/types.html index 18720a2..3fb31ef 100644 --- a/types.html +++ b/types.html @@ -76,7 +76,7 @@Header boost/endian/types.hpp -provides integer and floating point binary types with explicit control over +provides integer and floating point binary types with control over byte order, value type, size, and alignment. Typedefs provide easy-to-use names for common configurations.
These types provide portable byte-holders for integer data, independent of
@@ -102,7 +102,7 @@ arithmetic operators are +
, +=
, -
,
>>=
. Binary relational operators are ==
, !=
,
<
, <=
, >
, >=
.
Automatic implicit conversion to the underlying value type is provided. An -explicit conversion constructor from the underlying value type is provided.
+conversion constructor from the underlying value type is provided.The endian_example.cpp program writes a binary file containing four byte big-endian and little-endian integers:
@@ -207,6 +207,7 @@ will no longer be relying on unspecified behavior.Two scoped enums are provided:
enum class order {big, little, native}; + enum class align {no, yes};
One class template is provided:
@@ -349,7 +350,13 @@ usual operations on integers are supplied. { // C++11 features emulated if not available - enum class order {big, little, native}; + enum class order + { + big, // big-endian + little, // little-endian + native = implementation-defined // same as order::big or order::little + }; + enum class align {no, yes}; template <order Order, typename T, std::size_t n_bits, align A = align::no> @@ -361,13 +368,14 @@ usual operations on integers are supplied. // if BOOST_ENDIAN_FORCE_PODNESS is defined && C++11 POD's are not // available then these two constructors will not be present endian() noexcept = default; - explicit endian(T v) noexcept; + endian(T v) noexcept; endian& operator=(T v) noexcept; operator T() const noexcept; const char* data() const noexcept; - // arithmetic operations; additional operators provided by value_type + // arithmetic operations + // note that additional operations are provided by the value_type value_type operator+(const endian& x) noexcept; endian& operator+=(endian& x, value_type y) noexcept; endian& operator-=(endian& x, value_type y) noexcept; @@ -387,43 +395,44 @@ usual operations on integers are supplied. endian operator--(endian& x, int) noexcept; }; - typedef endian<order::big, float, 32, align::yes> big_align_float32_t; - typedef endian<order::big, double, 64, align::yes> big_align_float64_t; + // aligned big endian floating point types + typedef endian<order::big, float, 32, align::yes> big_align_float32_t; + typedef endian<order::big, double, 64, align::yes> big_align_float64_t; - // aligned little endian floating point types - typedef endian<order::little, float, 32, align::yes> little_align_float32_t; - typedef endian<order::little, double, 64, align::yes> little_align_float64_t; + // aligned little endian floating point types + typedef endian<order::little, float, 32, align::yes> little_align_float32_t; + typedef endian<order::little, double, 64, align::yes> little_align_float64_t; - // unaligned big endian floating point types - typedef endian<order::big, float, 32, align::no> big_float32un_t; - typedef endian<order::big, double, 64, align::no> big_float64un_t; + // unaligned big endian floating point types + typedef endian<order::big, float, 32, align::no> big_float32un_t; + typedef endian<order::big, double, 64, align::no> big_float64un_t; // unaligned little endian floating point types - typedef endian<order::little, float, 32, align::no> little_float32un_t; - typedef endian<order::little, double, 64, align::no> little_float64un_t; + typedef endian<order::little, float, 32, align::no> little_float32un_t; + typedef endian<order::little, double, 64, align::no> little_float64un_t; // aligned big endian signed integer types - typedef endian<order::big, int16_t, 16, align::yes> big_align_int16_t; - typedef endian<order::big, int32_t, 32, align::yes> big_align_int32_t; - typedef endian<order::big, int64_t, 64, align::yes> big_align_int64_t; + typedef endian<order::big, int16_t, 16, align::yes> big_align_int16_t; + typedef endian<order::big, int32_t, 32, align::yes> big_align_int32_t; + typedef endian<order::big, int64_t, 64, align::yes> big_align_int64_t; - // aligned big endian unsigned integer types - typedef endian<order::big, uint16_t, 16, align::yes> big_align_uint16_t; - typedef endian<order::big, uint32_t, 32, align::yes> big_align_uint32_t; - typedef endian<order::big, uint64_t, 64, align::yes> big_align_uint64_t; + // aligned big endian unsigned integer types + typedef endian<order::big, uint16_t, 16, align::yes> big_align_uint16_t; + typedef endian<order::big, uint32_t, 32, align::yes> big_align_uint32_t; + typedef endian<order::big, uint64_t, 64, align::yes> big_align_uint64_t; - // aligned little endian signed integer types - typedef endian<order::little, int16_t, 16, align::yes> little_align_int16_t; - typedef endian<order::little, int32_t, 32, align::yes> little_align_int32_t; - typedef endian<order::little, int64_t, 64, align::yes> little_align_int64_t; + // aligned little endian signed integer types + typedef endian<order::little, int16_t, 16, align::yes> little_align_int16_t; + typedef endian<order::little, int32_t, 32, align::yes> little_align_int32_t; + typedef endian<order::little, int64_t, 64, align::yes> little_align_int64_t; - // aligned little endian unsigned integer types - typedef endian<order::little, uint16_t, 16, align::yes> little_align_uint16_t; - typedef endian<order::little, uint32_t, 32, align::yes> little_align_uint32_t; - typedef endian<order::little, uint64_t, 64, align::yes> little_align_uint64_t; + // aligned little endian unsigned integer types + typedef endian<order::little, uint16_t, 16, align::yes> little_align_uint16_t; + typedef endian<order::little, uint32_t, 32, align::yes> little_align_uint32_t; + typedef endian<order::little, uint64_t, 64, align::yes> little_align_uint64_t; - // aligned native endian typedefs are not provided because - // <cstdint> types are superior for this use case + // aligned native endian typedefs are not provided because + // <cstdint> types are superior for that use case // unaligned big endian signed integer types typedef endian<order::big, int_least8_t, 8> big_int8_t; @@ -465,51 +474,56 @@ usual operations on integers are supplied. typedef endian<order::little, uint_least64_t, 56> little_uint56_t; typedef endian<order::little, uint_least64_t, 64> little_uint64_t; - // unaligned native endian signed integer types - typedef endian<order::native, int_least8_t, 8> native_int8_t; - typedef endian<order::native, int_least16_t, 16> native_int16_t; - typedef endian<order::native, int_least32_t, 24> native_int24_t; - typedef endian<order::native, int_least32_t, 32> native_int32_t; - typedef endian<order::native, int_least64_t, 40> native_int40_t; - typedef endian<order::native, int_least64_t, 48> native_int48_t; - typedef endian<order::native, int_least64_t, 56> native_int56_t; - typedef endian<order::native, int_least64_t, 64> native_int64_t; - - // unaligned native endian unsigned integer types - typedef endian<order::native, uint_least8_t, 8> native_uint8_t; - typedef endian<order::native, uint_least16_t, 16> native_uint16_t; - typedef endian<order::native, uint_least32_t, 24> native_uint24_t; - typedef endian<order::native, uint_least32_t, 32> native_uint32_t; - typedef endian<order::native, uint_least64_t, 40> native_uint40_t; - typedef endian<order::native, uint_least64_t, 48> native_uint48_t; - typedef endian<order::native, uint_least64_t, 56> native_uint56_t; - typedef endian<order::native, uint_least64_t, 64> native_uint64_t; + // unaligned native endian signed integer types + typedef implementation-defined_int8_t native_int8_t; + typedef implementation-defined_int16_t native_int16_t; + typedef implementation-defined_int24_t native_int24_t; + typedef implementation-defined_int32_t native_int32_t; + typedef implementation-defined_int40_t native_int40_t; + typedef implementation-defined_int48_t native_int48_t; + typedef implementation-defined_int56_t native_int56_t; + typedef implementation-defined_int64_t native_int64_t; + + // unaligned native endian unsigned integer types + typedef implementation-defined_uint8_t native_uint8_t; + typedef implementation-defined_uint16_t native_uint16_t; + typedef implementation-defined_uint24_t native_uint24_t; + typedef implementation-defined_uint32_t native_uint32_t; + typedef implementation-defined_uint40_t native_uint40_t; + typedef implementation-defined_uint48_t native_uint48_t; + typedef implementation-defined_uint56_t native_uint56_t; + typedef implementation-defined_uint64_t native_uint64_t; } // namespace endian } // namespace boost +The implementation-defined
text above is either
+big
or little
according to the endianness of the
+platform.
endian() = default; // C++03: endian(){}
endian() = default; // C++03: endian(){}
+-Effects: Constructs an object of type
endian<E, T, n_bits, A>
.
explicit endian(T v);
endian(T v);
-Effects: Constructs an object of type
endian<E, T, n_bits, A>
.Postcondition:
x == v,
wherex
is the constructed object.
endian& operator=(T v);
endian& operator=(T v);
-Postcondition:
x == v,
wherex
is the constructed object.Returns:
*this
.
operator T() const;
operator T() const;
-Returns: The current value stored in
*this
, converted tovalue_type
.
const char* data() const;
const char* data() const;
Returns: A pointer to the first byte of the endian binary value stored in
@@ -564,13 +578,10 @@ incrementing a variable in a record. It is very convenient to write: representation) regardless of whether a compiler treats char as signed or unsigned.*this
.
Classes with similar functionality have been independently developed by @@ -617,7 +628,7 @@ differs from endian representation size. Vicente Botet and other reviewers suggested supporting floating point types.
Last revised: -31 August, 2013
+12 August, 2014© Copyright Beman Dawes, 2006-2009, 2013
Distributed under the Boost Software License, Version 1.0. See www.boost.org/ LICENSE_1_0.txt