@disable
Leandro Lucarella
llucax at gmail.com
Fri Jan 15 05:21:00 PST 2010
Clemens, el 15 de enero a las 04:40 me escribiste:
> Andrei Alexandrescu Wrote:
>
> > Clemens wrote:
> > > Andrei Alexandrescu Wrote:
> > >
> > >> The main idea is to allow creation of noncopyable types by marking
> > >> this(this) as @disable.
> > >
> > > I must be missing something, but isn't this usually done by making the copy constructor private?
> >
> > Well one issue is that in D private has module granularity, which means
> > that inside a given module you could still create objects. That has the
> > advantage of obviating the need for "friend", but disables the private
> > constructor idiom.
> >
> > Andrei
>
> I thought about that, but it seemed to me that the D philosophy is that
> modules can be trusted to "do the right thing" internally. Then again,
> I can see how, due to its implicit nature, invoking a copy constructor
> "accidentally" may be easier than invoking a private method, leading to
> subtle bugs.
Exactly, that seems like a contradiction: we are confident that the module
author know what he is doing giving him rights to access private data, but
we are not so sure about certain functions...
I know it could be useful to have more granularity, but maybe we need
a new visibility attribute, like "module" (making "private" really
private, and "module" what "private" actually does). Changing "private"
meaning is probably a bad idea though, maybe private can be left as is and
add a "delete" visibility attribute (which would have the same effect than
@disable, but is more close to the current way to do things).
class X {
private this();
delete this(X);
}
It would be even more familiar to people coming from C++0x (C++1x! =P)
--
Leandro Lucarella (AKA luca) http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
MP: Cómo está, estimado Bellini? B: Muy bien, Mario, astrologando.
MP: Qué tengo? B: Un balcón-terraza.
MP: No, en mi mano, Bellini... B: Un secarropas!
MP: No, escuche bien, eh. Tiene B: El circo de Moscú.
números.
MP: No Bellini. Toma medidas. B: Un ministro.
MP: No Bellini, eh! Algunas son B: Una modelo, Mario!
de plástico y otras de madera.
MP: No, Bellini, no y no!
-- El Gran Bellini (Mario Podestá con una regla)
More information about the Digitalmars-d
mailing list