C++ Logo

std-proposals

Advanced search

Re: explicit class

From: Tae Lim Kook <uruwi_at_[hidden]>
Date: Mon, 11 Nov 2019 18:50:02 +0000
Not for or against, but this reminds me of Rust's default approach, where you have to explicitly #[derive(Copy, Clone /* &c. */)] to get the traits you want.

– T.

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Monday, 11 November 2019 13:47, Steve Weinrich via Std-Proposals <std-proposals_at_[hidden]> 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?
>
> Thanks in advance!

Received on 2019-11-11 12:52:36