const(X) member of Y
Maxim Fomin
maxim at maxim-fomin.ru
Wed Feb 6 21:30:18 PST 2013
On Wednesday, 6 February 2013 at 22:54:40 UTC, Dan wrote:
> This begs the question:
>
> Which of these do you choose and for what reasons:
> - this(this){}
This is natural way to define struct postblit. This fully
complies with current D spec. This should be used until postblit
constness problem is faced.
> - this(this)const{}
This is not normal way to define struct postblit but which
happens to work. Spec is silent about this. If you encounter
"postblit is not callable using const" message, you can
workaround the problem by making postblit const and forwarding
call to some other non-const method which actually does
postblitting. This is type system breakage which can be useful
until option 1 is fixed. Or you may use other workarounds.
> - this(const this){}
This is a tricky and unintuitive way to define simple struct
constructor which may be confused with postblit. It actually means
struct S { this(const S s){...} }
and can be written in this way to avoid confusion.
> Also, has any of this detailed information made it into the
> language spec?
#1 is fully defined in struct chapter. #2 is not defined. #3 is a
particular example of omitting parameter names like void foo(int)
{ }. D unlike C supports omitting parameter names not only in
function declaration, but in function definition too.
> Thanks
> Dan
More information about the Digitalmars-d
mailing list