C++ Logo

std-proposals

Advanced search

Re: explicit class

From: Magnus Fromreide <magfr_at_[hidden]>
Date: Wed, 13 Nov 2019 17:08:01 +0100
On Wed, Nov 13, 2019 at 01:01:26PM +0300, Andrey Semashev via Std-Proposals wrote:
> On 2019-11-13 11:39, Magnus Fromreide via Std-Proposals wrote:
> > On Mon, Nov 11, 2019 at 11:47:18AM -0700, 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.
> >
> > I do not say anything about wether this is useful or not but I dislike the
> > gracious co-opting of explicit so lets open up the bikeshed painting session.
> >
> > I would propose that you reuse "= delete" like this:
> >
> > class T = delete : private B { };
> >
> > The point of is that it it more logical to use "= delete" than "explicit" to
> > state that all defaulted members are deleted.
>
> This would make a forward declaration look misleading, wouldn't it?
>
> class T = delete;

I would expect a forward declaration to read

class T;

regardless of explicitness - is there any reason to distinguish explicit
classes in forward declarations?

/MF

Received on 2019-11-13 10:10:23