Subject: Re: [boost] Any interest in bitstream class?
From: Paul Long (plong_at_[hidden])
Date: 2013-06-29 23:09:03
On 6/29/2013 12:40 PM, Mathias Gaunard wrote:
> What should I do if I want to define the operators on my own
> user-defined type?
Write them. It should be easy. For example, this is all it takes for
ibitstream to support std::bitset:
template <size_t N>
ibitstream &operator>>(ibitstream &ibs, std::bitset<N> &bs)
bs = static_cast<long>(value);
> See Rob's response. I assumed ibitstream derived from istream. Is that
> not the case?
That is not the case. See my reply to Mathias' similar query at
> Does the ibitstream even use similar virtual functions and buffering
> mechanisms as istream?
Well, it follows std::istringstream and therefore std::istream. As far
as possible, ibitstream and bitbuf have the same member functions and
semantics as std::istringstream and std::stringbuf.
> I suspect writing the value directly to the stream (possibly after
> byte swapping) would be faster than shifts and bitwise ands and
> writing it byte per byte.
I agree. However, my main concern was stability through simplicity.
There is plenty of room for optimization, which I plan to do.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk