C++ Logo

std-proposals

Advanced search

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

From: Gašper Ažman <gasper.azman_at_[hidden]>
Date: Mon, 26 Dec 2022 22:03:16 +0000
see also std::forward_like in c++23.

On Mon, Dec 26, 2022 at 5:38 PM 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.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2022-12-26 22:03:30