C++ Logo

std-proposals

Advanced search

Proposal to simplify creating constructors

From: Oleksii Tarasiuk <o.tarasiuk_at_[hidden]>
Date: Thu, 6 Feb 2020 20:17:13 +0100
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.
  }
};




-- 
Best regards,
Oleksii Tarasiuk                          mailto:o.tarasiuk_at_[hidden]

Received on 2020-02-06 13:19:56