mirror of
https://github.com/boostorg/endian.git
synced 2025-08-01 05:24:39 +02:00
For now, revert to the general reorder template. Think about ways to make it safe and efficient.
git-svn-id: http://svn.boost.org/svn/boost/sandbox/endian@74353 b8fc166d-592f-0410-95f2-cb63ce0dd405
This commit is contained in:
@@ -21,9 +21,10 @@
|
||||
// -- reorder implementation approach suggested by tymofey, with avoidance of
|
||||
// undefined behavior as suggested by Giovanni Piero Deretta, and a further
|
||||
// refinement suggested by Pyry Jahkola.
|
||||
//
|
||||
// Q: Why no general reorder template? A: It wouldn't work for classes with more than
|
||||
// one member; each member must be reordered individually.
|
||||
// -- general reorder function template to meet requests for UDT support by
|
||||
// Vicente Botet and others.
|
||||
// -- general reorder function template implementation approach using std::reverse
|
||||
// suggested by Mathias Gaunard
|
||||
//
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
@@ -44,11 +45,16 @@ namespace endian2
|
||||
|
||||
// TODO: Need implementation
|
||||
// TODO: Need to verify the return does not invoke undefined behavior (as might happen
|
||||
// if there are unutterable floating point values, similar to the unutterable pointer
|
||||
// values on some architectures
|
||||
// if there are unutterable floating point values, such as happens with the unutterable
|
||||
// pointer values on some architectures
|
||||
inline float reorder(float x);
|
||||
inline double reorder(double x);
|
||||
|
||||
// TODO: Would pass by value be better for the following functions?
|
||||
|
||||
template <class T>
|
||||
inline T reorder(const T& x);
|
||||
|
||||
template <class T>
|
||||
inline T big(const T& x);
|
||||
// Return: x if native endianness is big, otherwise reorder(x);
|
||||
@@ -109,6 +115,18 @@ namespace endian2
|
||||
| (step16 & 0xFF00FF00FF00FF00) >> 8;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
inline T reorder(const T& x)
|
||||
{
|
||||
T tmp;
|
||||
std::reverse(
|
||||
reinterpret_cast<const char*>(&x),
|
||||
reinterpret_cast<const char*>(&x) + sizeof(T),
|
||||
reinterpret_cast<char*>(&tmp));
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T big(const T& x)
|
||||
{
|
||||
|
Reference in New Issue
Block a user