C++ Logo

std-proposals

Advanced search

Re: user copy constructor

From: connor horman <chorman64_at_[hidden]>
Date: Thu, 12 Dec 2019 15:21:06 -0500
Seems interesting. Would this also be extended to move constructors similarly?

On Thu, 12 Dec 2019 at 15:17, Mario Charest via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> Hello Everyone,
>
> Sorry if this has been discuss previously.
>
> Imagine a class with 20 variables, out of these variable one should not be copied by the copy constructor
>
> class Foo {
> std::vector<int> first;
> std::list<int> second;
> ...
> void *no_copy;
>
> Foo (const Foo &);
> }
>
> Writing the Foo copy constructor is detious, error prone and leads to higher maintenance. But what if one could create the copy constructor in such a way that it would tell the compiler to default copy construct all variables, except one (or more)
>
> Foo::Foo(const Foo &) :! no_copy(nullptr)
> {
> }
>
> Notice the:!
>
> Did not put much though into the details, but wanted to first get a feel if this make sense.
>
> - Regards
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2019-12-12 14:23:44