C++ Logo

std-proposals

Advanced search

Re: explicit class

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Tue, 12 Nov 2019 01:45:44 +0300
On 2019-11-11 21:47, Steve Weinrich via Std-Proposals wrote:
> This is an idea that has been roaming around my head for some 20 years!
>
> As we know, there is a list of some 15 (or so) operations (construction,
> assignment, copy, move, conversion, etc.) that the simple statement:
> “class T {};” defines.
>
> If one wishes some control over this behavior, one has to be
> knowledgeable in all that the compiler provides. In non-C++ terms, one
> has to say (modern use: =delete), “I don’t want that, I don’t want this,
> etc.” The compiler provides no aid for this!
>
> My notion is to reverse this via “explicit class T {};”. While I am
> sure there are some details that would need to be debated, this would
> eliminate (most) everything that the compiler defines for you. Thus, if
> you wanted something, you would have to define it or use “ = default”
> (yes, I am aware that would require extending “= default” to more items
> – seems OK to me). The obvious advantage is that the compiler now
> provides some help, in that using something that is not defined will
> yield a compiler error.
>
> Does anyone know if this has been proposed before? If not, what do you
> think?

I don't see a practical reason why someone would want to mark a class
explicit. Sure, there are cases when one wants to remove some operations
on the class, but I fail to see a case when I would want to remove
everything.

Also, does your proposal remove the destructor as well?

Received on 2019-11-11 16:48:07