C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] D2190R0 Proposal of Designated Constructor Parameters (DRAFT 1)
From: Zhihao Yuan (zy_at_[hidden])
Date: 2020-06-16 23:48:16


On Tuesday, June 16, 2020 6:57 PM, Andrew Tomazos via Std-Proposals <std-proposals_at_[hidden]> wrote:

> Feedback appreciated.

Requiring the caller-side designators to be
named after the private names is a major
restriction. First, a coding style that you are
conformable with can be toxic to someone
else. Second, you simply cannot initialize
a class with pimpl, because no meaningful
data members are named when the
constructors are declared.

Your proposal seems to model constructor
designators after default member initializers.
How about create a new form of default
member initializers?

class Rect
{
public:
Rect(int h, int w) [.height, .width]
: area_(h * w)
{}
Rect() : height_(0), width_(0) {}

private:
int height_ = .height;
int width_ = .width;
int area_ = 0;
};

Now you don't need extra rules to allow
conversions from designated constructor
parameters to data members, because
they are ordinary function parameters.
Also, by decoupling the designator names
with the data member names, you can
designate initialize classes with pimpl.

--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
_______________________________________________



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

Standard Proposals Archives on Google Groups