C++ Logo

std-proposals

Advanced search

Re: [std-proposals] [[packed]] std::unaligned

From: Thiago Macieira <thiago_at_[hidden]>
Date: Fri, 08 Dec 2023 17:59:19 -0800
On Friday, 8 December 2023 17:44:25 PST Frederick Virchanza Gotham via Std-
Proposals wrote:
> On Fri, Dec 8, 2023 at 11:49 PM Thiago Macieira wrote:
> > Something like it, but not that. The operations defined there must either
> > be a very restricted set (get and set, probably) or be based on what the
> > template type is. You can't do shifts on floating point and you can't do
> > arithmetic on structures.
>
> Yeah but there's no harm in defining those extra operators like
> bit-shifting . . . you won't get a compiler error unless the
> programmer actually tries to bit-shift an 'unaligned<double>'.

Right, because you used templates. But I don't think the standard would be
that lax in defining the interface.

> To be honest though I'd go with my original code that doesn't apply
> any constraints, and just let the compiler give the following error:
>
> <source>:25:13: error: invalid operands to binary expression
> ('double' and 'float')
> 25 | tmp &= std::forward<U>(u);
> | ~~~ ^ ~~~~~~~~~~~~~~~~~~
>
> <source>:63:9: note: in instantiation of function template
> specialization 'unaligned<double>::operator&=<float>' requested here
> 63 | obj &= 4.2f;

That might be three levels deep in template expansion, making the developer's
life more difficult than necessary.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2023-12-09 01:59:22