C++ Logo

std-proposals

Advanced search

Re: [std-proposals] cvhost : Re-use CVness of object

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Mon, 26 Dec 2022 20:07:49 +0200
On Mon, 26 Dec 2022 at 19:38, Frederick Virchanza Gotham via
Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> Take the following sample code:
>
> struct Monkey {
> int &i;
> };
>
> int main(void)
> {
> int num = 5;
> Monkey const m{num};
> m.i = 7;
> }
>
> On the last line there, I'm able to assign to 'i' even though 'm' is const.
>
> I propose that we should be able to determine the CV qualifiers of the object and re-use them on the member objects, maybe something like:
>
> struct Monkey {
> int cvhost &i;
> };
>
> So if you have a const object of type 'Monkey', then 'i' is a reference to const. If you have a non-const volatile object of type 'Monkey', then 'i' is a reference to volatile. If you have a const volatile object of type 'Monkey', then 'i' is a reference to const volatile.

So something really close to this thing here
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/n4908.html#propagate_const

Received on 2022-12-26 18:08:02