|
Boost : |
Subject: Re: [boost] [dynamic_bitset] Endianess and Adaption Vs Copying
From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2012-05-03 13:22:28
Joel wrote:
> dynamic_bitset provides a constructor that takes raw data as input. If
> the source for that input has the bits ordered consecutively (which would
> allow one to change the block type without changing the ordering of the bits)
> then the constructor will not function properly.
Perhaps you could post a short example of some code that you think
would fail?
I was a bit surprised to find that it has this:
template <typename Block>
class dynamic_bitset {
template <typename BlockInputIter>
dynamic_bitset(BlockInputIter first, BlockInputIter last) { ...
So you can do this:
const char* data = ......; // From a "platform independent" binary file.
dynamic_bitset<unsigned int> b(data,data+size);
This probably doesn't do what you want, but not for endianness reasons;
it seems to initialise each int-sized block with one byte of data,
leaving the other 24 bits unset. If you write this:
const char* data = ......; // From a "platform independent" binary file.
dynamic_bitset<unsigned char> b(data,data+size);
then I believe it will always work. If you write this:
const char* data = ......; // From a "platform independent" binary file.
const int* data_i = static_cast<const int*>(data);
dynamic_bitset<int> b(data_i,data_i+size);
then you get endianness problems. But you would have the same trouble
if you tried to initialise e.g. a vector<int> in that way.
> At minimum, the bit-ordering imposed by dynamic-bitset should be
> explicitly documented.
The BIT ordering? No, bit ordering is always the same. You never need
to re-order the bits within a byte.
(What am I missing?)
Regards, Phil.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk