Boost logo

Boost :

From: Zach Laine (whatwasthataddress_at_[hidden])
Date: 2024-12-05 18:26:36


On Thu, Dec 5, 2024 at 10:47 AM Peter Dimov via Boost
<boost_at_[hidden]> wrote:
>
> Zach Laine wrote:
> > On Thu, Dec 5, 2024 at 7:31 AM Peter Dimov via Boost
> > <boost_at_[hidden]> wrote:
> > >
> > > Alexander Grund wrote:
> > > > So span<void const> then or as that isn't accepted span<char const>
> > > > assuming
> > > > sizeof(char)==sizeof(byte)
> > >
> > > span<void const> doesn't exist, though. I was giving it as an example
> > > of something that I would have added to the hypothetical hash2::span,
> > > but no existing span library has it.
> > >
> > > If we limit ourselves to std::span, I suppose we can just add three
> > > (or
> > > four) overloads, one per byte type.
> > >
> > > (Four because of char8_t.)
> >
> > This part confuses me. It's always safe to cast to void const *; what not just
> > have a single template that takes a std::span<T>, and cast it's .begin() and
> > .end() to void const *?
>
> If you mean this
>
> template<class T> void update( std::span<T> sp );
>
> then the reason to not use it is that you can't pass things like `string` and
> `vector<unsigned char>` and `char[65536]` directly because deduction will
> not work.
>
> I'm not particularly fond of the user-facing syntax being
>
> hash.update( std::span{buffer} );
>
> instead of
>
> hash.update( buffer );

Thanks, that makes sense. Looking at the docs, I think I get it now
-- this is a user-provided API that your lib requires, right? If
that's the case, I think I'd also require what you have, since there's
no single concrete span type you could write there.

An alternative might be to simply change the API depending on the
value of __cplusplus -- void* + size_t before C++20, and
std::span<std::byte> in C++20 and later. I realize some people might
hate this. :)

Zach


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