C++ Logo

std-proposals

Advanced search

Re: [std-proposals] <type_traits> std::contains_mutable

From: Simon Schröder <dr.simon.schroeder_at_[hidden]>
Date: Sun, 16 Nov 2025 13:49:30 +0100
> On Nov 14, 2025, at 3:38 PM, Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> Similarly on desktop PC's, a page of memory can be toggled from
> writable to read-only.

How is that supposed to work? When I declare an integer const and initialize it, should it be written to an individual page that is then made read-only? That would be really wasteful. Sure, the compiler could reserve a page for read-only objects that it makes writeable when it needs to add another variable. But, that would be slow and would add nothing for safety. Furthermore, we would not want to mandate this because it would disallow many optimizations. And obviously the compiler can (at least in theory) already figure out if something contains a mutable and place objects in the proper memory areas. We don’t need anything else in the standard for this kind memory optimization to work.

I would claim, however, that it could be useful for the programmer to know this. Especially in the context of reflection this could be helpful. We still need good motivating examples for this. You haven’t provided any motivation so far how this would benefit the programmer (and not the compiler).

Received on 2025-11-16 12:49:44