C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: What even happened to <net> and byte swapping?
From: David Bakin (david_at_[hidden])
Date: 2021-02-26 09:48:36


I believe it would be more aligned with the C++ philosophy that this newly
standardized feature be as fundamental as possible - as close to the metal
as possible - and thus be a byte-swap proposal and not a
"make-it-this-endian" proposal. "make-it-this-endian" is built from two
lower level primitives: is_little_endian? and byteswap. To standardize
"make-it-this-endian" would leave the use cases needing simply byteswap out
in the non-standardized cold. And yet it would be easy to _build_
"make-it-this-endian" on top of is_little_endian? (now called `std::endian`
in C++20) and byteswap.

(BTW, and off topic, I see that `std::endian` doesn't support the VAX ...
should it have been a _template_, like `std::endian<type>` so that integers
and floats could have different endianness?)

-- David

On Fri, Feb 26, 2021 at 7:33 AM Jason McKesson via Std-Discussion <
std-discussion_at_[hidden]> wrote:

> On Fri, Feb 26, 2021 at 10:08 AM Edward Catmur via Std-Discussion
> <std-discussion_at_[hidden]> wrote:
> >
> > On Fri, Feb 26, 2021 at 1:13 PM Matthew Woehlke via Std-Discussion <
> std-discussion_at_[hidden]> wrote:
> >>
> >> Overloads taking `span` might be nice, also.
> >
> >
> > How can you convert a span of bytes without knowing the layout of the
> fields within it? Say you have a range of 10 bytes that is {int64, uint32,
> 4x int8, int16}?
>
> Presumably, it'd look something like this:
>
> ```
> span<std::byte> data = ...
> data = in_place_from_le<std::int64_t>(data);
> data = in_place_from_le<std::int32_t>(data);
> data = in_place_from_le<std::int8_t[4]>(data);
> data = in_place_from_le<std::int16_t>(data);
> ```
>
> These functions return a span that has been incremented by the size of
> the data type. Non-in-place versions (returning rvalues) would take
> their `span`s by lvalue reference and offset them directly or return a
> struct containing the value and the offsetted `span`. I would prefer
> the lvalue reference version.
>
> >And what if there's IEEE floats in there?
>
> That's just another type.
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>



STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups