|
Boost : |
Subject: Re: [boost] [endian] Use in Hash algorithms
From: Scott McMurray (me22.ca+boost_at_[hidden])
Date: 2010-05-29 10:02:45
On 29 May 2010 00:05, Terry Golubiewski <tjgolubi_at_[hidden]> wrote:
> What is Magic<int, int>?
>
Something that needs implementing as a test of an endian library.
For example, I could implement it with what I wrote as follows:
template <int In, int Out>
struct Magic {
array< uint_t<In>::least, Out/In > in;
unsigned i;
Magic() : i() {}
void put(uint_t<In>::least x) { in[i++] = x; }
uint_t<Out>::least get() const {
array<uint_t<Out>::least, 1> out;
pack<big_bit, In, Out>(in, out);
return out[1];
}
};
With Beman's it would be something like this:
template <int In, int Out>
struct Magic {
union {
array< endian<big, uint_t<In>::exact>, Out/In> in;
endian<big, uint_t<Out>::exact> out;
};
array< uint_t<In>::least, Out/In > in;
unsigned i;
Magic() : i() {}
void put(uint_t<In>::least x) { in[i++] = x; }
uint_t<Out>::least get() const {
return out;
}
};
I think, anyways, though it requires C++0x unions.
That, of course, can't handle Ins or Outs that are not multiples of CHAR_BIT.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk