
On 6/4/06, Beman Dawes <bdawes@acm.org> wrote:
* Provision has been made for native endianness. Not implemented yet.
I've implemented it in the attached header and added the corresponding typedefs. It currently memcpy's the bytes around. I don't know whether it would be preferable to use BOOST_LITTLE_ENDIAN and call (load|store)_(big|little)_endian instead.
* More explicit names have been given to the forty-four typedefs. A careful explanation of the naming rationale has been added to the docs.
Much nicer, and different enough from stdint for big8_t to not look immediately like a char. I would also, as Eric suggests, prefer aligned_ as the prefix instead of just a.
* I haven't looked at Scott McMurray's exact.hpp header yet, so that may kick off yet more changes to come.
It's basically just the native endian types, just in a different interface. With those in yours, it's not terribly important. I would like to keep a similar interface as a possibility and think it's possible to do so without changing the current one at all (only adding to it): boost::endian< boost::big, boost::uint_t<24> > x; Unfortunately, I haven't gotten any of my attempts at specialisation to work. Here's what I consider the most promising failed attempt, in the hopes that someone can spot the problem: template <endianness E, std::size_t n_bits, std::size_t n_bytes> class endian< E, boost::int_t<n_bits>, n_bytes > : integer_cover_operators< endian< E, boost::int_t<n_bits>, n_bytes >, typename boost::int_t<n_bits>::least > { BOOST_STATIC_ASSERT( n_bits % CHAR_BIT == 0 ); public: typedef typename boost::int_t<n_bits>::least value_type; endian() {} endian(value_type i) : value(i) {} operator value_type() { return value; } private: endian< E, value_type, n_bits/CHAR_BIT > value; }; template <endianness E, std::size_t n_bits, std::size_t n_bytes> class endian< E, boost::uint_t<n_bits>, n_bytes > : integer_cover_operators< endian< E, boost::uint_t<n_bits>, n_bytes >, typename boost::uint_t<n_bits>::least > { BOOST_STATIC_ASSERT( n_bits % CHAR_BIT == 0 ); public: typedef typename boost::uint_t<n_bits>::least value_type; endian() {} endian(value_type i) : value(i) {} operator value_type() { return value; } private: endian< E, value_type, n_bits/CHAR_BIT > value; }; The other change I made to the header was to add STATIC_ASSERTs in the various templates. I could see someone using endian<little, int, 3>, which would be very confusing if they ever ported to a platform with 16-bit ints. One other question: Will the library being using "bytes" as 8 bits or as the same size as a char? ( I understand there are many people in various C++ IRC channels with toasters that have 13-bit chars :P ) ~ Scott