Boost logo

Boost :

Subject: Re: [boost] [boost::endian] Summary of discussion #1
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2010-06-03 13:59:51


Scott McMurray wrote:
> On 3 June 2010 12:30, Terry Golubiewski <tjgolubi_at_[hidden]> wrote:
> > Tom wrote:
> >>
> >> endian::cast<big_to_host>() //explicit direction
> >> endian::cast<from_litle>() //"to_host" is implicit
> >> endian::cast<to_big>() //"from_host" is implicit
> >
> > Is it imporant that these names are templated? What are
> > the advantages of this templated-tagged design over..
>
> I also find it odd that the direction is mixed in with the endianness.

We discussed this previously. I had suggested to<>() and from<>() as well as endian_cast<>. Tomas noted the symmetry of the cast notation for all three cases, but that necessarily requires the direction in the template argument.

> I'd expect something like to_host_endian and from_host_endian, with a
> policy type for the endianness.

to_host_endian<little>() just barely implies conversion from little endian to host endianness to my mind. endian_cast<from_little>() is clearer to me. from<little>() is perfectly clear, but doesn't express that a copy is returned (versus in-place reordering) while the new-style cast syntax more readily implies it.

> The only advantage I see of the explicit one is that it theoretically
> allows cast<big_to_little>, but that would mean defining a number of
> types quadratic in the number of endiannesses. It clearly has no
> speed benefit over to_host then from_host on typical machines. I'm
> also not certain that it's even a useful operation.

As discussed previously, there are occasions when the reordering is for translation without the need to modify or inspect the data in the process. For those cases, going from a specific endianness to a specific endianness is appropriate. I don't imagine those uses are frequent, but it is rather nice that they can use the same syntax as the others.

_____
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