C++ Logo


Advanced search

Re: D2190R0 Proposal of Designated Constructor Parameters (DRAFT 1)

From: Zhihao Yuan <zy_at_[hidden]>
Date: Wed, 17 Jun 2020 04:48:16 +0000
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
Rect(int h, int w) [.height, .width]
: area_(h * w)
Rect() : height_(0), width_(0) {}

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.

Received on 2020-06-16 23:51:36