C++ Logo

std-proposals

Advanced search

Re: Proposal to simplify creating constructors

From: Михаил Найденов <mihailnajdenov_at_[hidden]>
Date: Fri, 7 Feb 2020 09:57:04 +0200
On Thu, Feb 6, 2020 at 9:17 PM Oleksii Tarasiuk via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Hi all!
>
> Let's assume we have the following class:
> // [Case 1]
> class Person {
> private:
> string name_;
> Date birthDate_;
> //.... other data members.
> public:
> Person(string&& name, Date const& birthDate, SomeOtherType someOtherArg)
> : name_(forward<string>(name), birthDate_(birthDate)
> {
> // use someOtherArg to further init the instance of Person.
> }
> };
>
> I propose to add support for the following simplified form which is
> equivalent to [Case 1]:
>
> // [Case 2]
> class Person {
> private:
> string name_;
> Date birthDate_;
> //.... other data members.
> public:
> Person(auto&& .name_, auto const& .birthDate_, SomeOtherType
> someOtherArg)
> {
> // use someOtherArg to further init the instance of Person.
> }
> };
>
>
By this model the constructor must be inline which is often not
possible/recommended/desirable.
If it is not inline, things begin to become tricky, as the declaration will
still have to name the members (so the compiler knows for which definition
to look for)
Members being part of the ctor declaration is ... questionable as it is no
longer just an interface.

The manual duplication is definitely annoying, but I am afraid a bunch of
new corner rules and new behavior will skew the scales to "not worth the
effort" just enough.


>
>
> --
> Best regards,
> Oleksii Tarasiuk mailto:o.tarasiuk_at_[hidden]
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2020-02-07 01:59:55