Subject: Re: [boost] [endian] endian flip and endian domain
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2010-06-08 12:59:38
Gottlob Frege wrote:
> On Tue, Jun 8, 2010 at 11:52 AM, Stewart, Robert
> <Robert.Stewart_at_[hidden]> wrote:
> > Gottlob Frege wrote:
> > It would be possible to also include the cases in which the
> > input and output endiannesses are specified (the filter
> > case), but those lead right back to confusion about the
> > template argument order.
> Technically, the output endianness would take the place of the int.
That doesn't fit the pattern because the result is an int, not a "big endian," for example. Hence the cast is to int first.
> But then you'd need a secondary cast, I suppose. ie
> big j = endian_cast<big, little>(k);
> int i = reinterpret_cast<int>(endian_cast<big, little>(k));
Those aren't casts following the pattern of the new-style casts in the language.
> > Notice that endian_wrapper<> needed a means to get the
> > value. I don't see the value of a wrapper type that
> > specifies the endianness but gives no means to access the value.
> Alternatively, you would reinterpret_cast<> internally. Otherwise I
> worry about the value of the wrapper - is it converted to host or not?
> I could live with something like:
> wrapper.data() // raw data. or raw_data() or raw() or...
> wrapper.value() // converted to host *value*
I could live with raw() and host(). In fact, the copying conversion logic could actually be on that class:
The latter returns the value in the unconverted order as described by w's type's nested type "type." (Whew!)
The former two will implement endianness conversion (or not) depending upon w's endianness and the template argument. That is, when the two types are the same, just return raw(). When they differ, do the conversion and return the result.
> is slightly nicer, but
> endian_cast<T, big_endian>()
> isn't really much worse (only 2 characters! (not really...))
Actually, you're comparing those wrong. convert_from<big_endian>() means convert from big endian to host order. The equivalent cast requires knowing the host order: endian_cast<T, native_endian>(). I like the former better because it reads nicely, not just that it is shorter.
> The benefit of the latter is consistency and explicitness.
Notice how easy it was to get wrong! It is also not consistent with the normal casts.
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com
IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk