Date: Mon, 26 Dec 2022 18:52:17 +0100
Hey, I think this can and should be solved by proper getters. "POD" type
structs should not contain references, and classes should not expose their
reference members for this exact reason.
On Mon, Dec 26, 2022, 18: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.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
structs should not contain references, and classes should not expose their
reference members for this exact reason.
On Mon, Dec 26, 2022, 18: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.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
Received on 2022-12-26 17:52:35