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