Boost logo

Boost :

Subject: Re: [boost] [endian] endian flip and endian domain
From: Gottlob Frege (gottlobfrege_at_[hidden])
Date: 2010-06-08 11:13:09


On Tue, Jun 8, 2010 at 10:39 AM, Gottlob Frege <gottlobfrege_at_[hidden]> wrote:
> <Replying to the entire naming thread, not one message in particular>
>
> convert seems like the best word. To me.
>

While I'm at it. My other thoughts on endian:

- I agree that the operators on an endian type are dangerous and
should be separated. (I also think operators on atomics are
dangerous, but that's another story.)

- I think we should consider that read on endian types is dangerous -
that is what the 'function-style' seems to be saying. ie an endian
type that I can read from will be read from multiple times and be
inefficient. But useful at times. So separated?

- so am I suggesting a base endian type that can't even be read? Possibly.

Note that the endian_cast<> discussion mentioned that it didn't follow
the cast<> syntax exactly, because return type and parameter type are
the same. This is essentially because we want to take the source int
and cast it to an endian, then cast it back to an int, all because we
didn't/couldn't define our source value as an endian type.
ie

   int j = from_big_endian_file();
   int i = endian_cast<big>(j);

should really be (if using types)

   big_endian_int j = from_big_endian_file();
   int i = endian_cast<int>(j);

or

   int i = endian_cast<int>(reinterpret_cast<big_endian_int>(j));

That's just too much to type. (And not necessarily the right names,
but leave that aside for now. I'm purposely using 'big_endian_int'
instead of trying to use a decent name, to avoid the naming
discussions)

So, I'm not sure if this can work out, but if we decide that
endian-types and type-safety is important, then endian_cast<> (or
convert, or...) should *only take an endian type*.
Then we get

   big_endian_int j = from_big_endian_file();
   int i = endian_cast<int>(j); // OK

   int k = from_big_endian_file();
   int i = endian_cast<int>(k); // FAILS - not sure endian type for k

but then allow specifying the type for k:

   int i = endian_cast<int, big_endian_int>(k); // OK - k is
reinterpreted as big_endian_int

Does this make sense? It's still a bit vague in my mind, but I'm just
wondering if we can somehow manage to use the same functions and
syntax in both the typed and untyped scenarios.

Tony


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk