C++ Logo

std-proposals

Advanced search

Re: Using `= default; ` Constructors to Remove Boilerplate Constructors

From: Viktor Kireev <vitech-job_at_[hidden]>
Date: Thu, 06 Feb 2020 12:53:35 +0300
On Thursday, 6 February 2020 08:00:06 MSK Alex Brachet-Mialot via Std-
Proposals wrote:
> Hi all,
>
> I just wanted to float this idea that I have had for a while.
>
> I find many constructors often follow this format Type(a_t a, b_t b) :
> a(a), b(b) {}. This can get tedious quickly and look very ugly. Such
> types can sometimes be aggregates which solves this problem, but not
> always, aggregates have prerequisites that very few types can
> realistically follow.
>
> I was thinking that `= default` could be used in this circumstance.

What types should this work for?

class C {
    std::unique_ptr<int> a;

public:
    C(std::unique_ptr<int> a) = default;
};

What should the compiler do?

-- 
Victor Kireev

Received on 2020-02-06 03:56:15