On 2016-04-04 16:55, Peter Dimov wrote:
Andrey Semashev wrote:
I think it's not Boost.Endian's job to deal with FP implementations. Or integer implementations, for that matter.
Dealing with different implementations is technically outside the charter of an "endianness" library. The end goal, however, is to let one read and write integers and floats in non-native formats. And when those non-native formats have a representation that is not a simple byteswap away from the native one, it would be kind of useful if the library still worked.
IMHO, if you need something more than a byte swap then you need a different library.
The interface can be defined to require a certain implementation of float or to simply ignore the implementation and consider input as opaque sequence of bytes. The implementation of that interface should just reorder bytes in that sequence, as requested, and do nothing more than that.
The interface could obviously be defined in various ways. What specific interface do you suggest?
Well, in some of the projects I work on we have something as simple as: void write_be32(std::uint32_t n, void* p); std::uint32_t read_be32(const void* p); // etc. template< typename T, std::size_t Size = sizeof(T) > struct big_endian; // Specializations for different values of Size template< typename T > struct big_endian< T, 4 > { static void write(T n, void* p) { write_be32(n, p); } static T read(const void* p) { return read_be32(p); } }; // ditto for little endian As simplistic and error prone as it may look, this basic interface is enough to build higher level and more specialized tools upon.