C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] Proposal of constpub (DRAFT 1)
From: Matthew Woehlke (mwoehlke.floss_at_[hidden])
Date: 2020-01-13 14:32:10


On 13/01/2020 13.14, Andrew Tomazos wrote:
> On Tue, Jan 14, 2020 at 3:15 AM Matthew Woehlke wrote:
>> I would rather see:
>>
>> class foo
>> {
>> public:
>> using x = std::as_const(m_x);
>> protected:
>> int m_x;
>> }
>
> This doesn't address the final concern in the paper, removing the need to
> create two different names for the same thing. ie In your example the two
> names `x` and `m_x` rather than just the one name `x`.

True, but TBH that is IMHO the least important aspect of the proposal.
I'm much less bothered by repeating a name than by having to use a
member function when what I really want is read-only access to a member
variable. The latter affects *my users*. The former only affects me.

Combine that with other features of my (counter)proposal:

- Does not need new keywords.

- Does not add an ambiguity issue for derived classes¹.

- Looks similar to, or can be implemented using, a feature that has
already been proposed and is more widely useful.

-- 
Matthew

STD-PROPOSALS list run by std-proposals-owner@lists.isocpp.org

Standard Proposals Archives on Google Groups