Re: this() not executing code on structs

2009-10-23 Thread Steven Schveighoffer
On Thu, 22 Oct 2009 12:50:21 -0400, grauzone n...@example.net wrote: dsimcha wrote: == Quote from grauzone (n...@example.net)'s article Andrei Alexandrescu wrote: I'd really like to know why scope x = new X(); is unsafe, while encouraging doing exactly the same with structs seems to be a

Re: this() not executing code on structs

2009-10-23 Thread Don
Bartosz Milewski wrote: Andrei Alexandrescu Wrote: this() { myCount = count++; } // ERROR It's worse than that. Try this: struct foo { this(int dummy = 0) { writeln(Default constructor);} } foo x = foo(); Nothing gets printed. If default constructors are disallowed, so

Re: this() not executing code on structs

2009-10-23 Thread Andrei Alexandrescu
Don wrote: Bartosz Milewski wrote: Andrei Alexandrescu Wrote: this() { myCount = count++; } // ERROR It's worse than that. Try this: struct foo { this(int dummy = 0) { writeln(Default constructor);} } foo x = foo(); Nothing gets printed. If default constructors are

Re: this() not executing code on structs

2009-10-23 Thread Denis Koroskin
On Fri, 23 Oct 2009 18:46:47 +0400, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: Don wrote: Bartosz Milewski wrote: Andrei Alexandrescu Wrote: this() { myCount = count++; } // ERROR It's worse than that. Try this: struct foo { this(int dummy = 0) {

Re: this() not executing code on structs

2009-10-23 Thread Andrei Alexandrescu
Denis Koroskin wrote: On Fri, 23 Oct 2009 18:46:47 +0400, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: Don wrote: Bartosz Milewski wrote: Andrei Alexandrescu Wrote: this() { myCount = count++; } // ERROR It's worse than that. Try this: struct foo { this(int

Re: this() not executing code on structs

2009-10-23 Thread Denis Koroskin
On Fri, 23 Oct 2009 19:40:33 +0400, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: Denis Koroskin wrote: On Fri, 23 Oct 2009 18:46:47 +0400, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: Don wrote: Bartosz Milewski wrote: Andrei Alexandrescu Wrote: this() {

Re: this() not executing code on structs

2009-10-23 Thread grauzone
Steven Schveighoffer wrote: On Thu, 22 Oct 2009 12:50:21 -0400, grauzone n...@example.net wrote: dsimcha wrote: == Quote from grauzone (n...@example.net)'s article Andrei Alexandrescu wrote: I'd really like to know why scope x = new X(); is unsafe, while encouraging doing exactly the same

Re: this() not executing code on structs

2009-10-23 Thread Denis Koroskin
On Sat, 24 Oct 2009 03:28:02 +0400, Denis Koroskin 2kor...@gmail.com wrote: On Fri, 23 Oct 2009 19:40:33 +0400, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: Denis Koroskin wrote: On Fri, 23 Oct 2009 18:46:47 +0400, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote:

Re: this() not executing code on structs

2009-10-22 Thread grauzone
dsimcha wrote: == Quote from grauzone (n...@example.net)'s article Andrei Alexandrescu wrote: I'd really like to know why scope x = new X(); is unsafe, while encouraging doing exactly the same with structs seems to be a perfectly fine idea. Allocating structs on the stack is obviously not any

Re: this() not executing code on structs

2009-10-22 Thread grauzone
dsimcha wrote: == Quote from grauzone (n...@example.net)'s article Andrei Alexandrescu wrote: I'd really like to know why scope x = new X(); is unsafe, while encouraging doing exactly the same with structs seems to be a perfectly fine idea. Allocating structs on the stack is obviously not any

Re: this() not executing code on structs

2009-10-22 Thread Andrei Alexandrescu
grauzone wrote: dsimcha wrote: == Quote from grauzone (n...@example.net)'s article Andrei Alexandrescu wrote: I'd really like to know why scope x = new X(); is unsafe, while encouraging doing exactly the same with structs seems to be a perfectly fine idea. Allocating structs on the stack is

Re: this() not executing code on structs

2009-10-22 Thread grauzone
Andrei Alexandrescu wrote: grauzone wrote: dsimcha wrote: == Quote from grauzone (n...@example.net)'s article Andrei Alexandrescu wrote: I'd really like to know why scope x = new X(); is unsafe, while encouraging doing exactly the same with structs seems to be a perfectly fine idea.

Re: this() not executing code on structs

2009-10-22 Thread Andrei Alexandrescu
grauzone wrote: Andrei Alexandrescu wrote: grauzone wrote: dsimcha wrote: == Quote from grauzone (n...@example.net)'s article Andrei Alexandrescu wrote: I'd really like to know why scope x = new X(); is unsafe, while encouraging doing exactly the same with structs seems to be a perfectly

this() not executing code on structs

2009-10-21 Thread Andrei Alexandrescu
Today, structs can't write their own this(). There aren't very solid reasons for that except that it makes language implementation more difficult. I wonder how much of a problem that could be in practice. I realized today that the Counted example - a classic C++ primer example featuring a

Re: this() not executing code on structs

2009-10-21 Thread zoli
Andrei Alexandrescu Wrote: Today, structs can't write their own this(). There aren't very solid reasons for that except that it makes language implementation more difficult. If the new operator for the class is redesigned to have multiply allocation types (allocate on heap, allocate on

Re: this() not executing code on structs

2009-10-21 Thread dsimcha
== Quote from zoli (z...@freemail.hu)'s article Andrei Alexandrescu Wrote: Today, structs can't write their own this(). There aren't very solid reasons for that except that it makes language implementation more difficult. If the new operator for the class is redesigned to have multiply

Re: this() not executing code on structs

2009-10-21 Thread zoli
If the new operator for the class is redesigned to have multiply allocation types (allocate on heap, allocate on stack, etc.?), there is no main drawback of using classes instead of structs for small objects( like vec2, vec3) as well. Yes there is. How about the cost of storing vtbl

Re: this() not executing code on structs

2009-10-21 Thread dsimcha
== Quote from zoli (ga...@freemail.hu)'s article If the new operator for the class is redesigned to have multiply allocation types (allocate on heap, allocate on stack, etc.?), there is no main drawback of using classes instead of structs for small objects( like vec2, vec3) as well.

Re: this() not executing code on structs

2009-10-21 Thread Denis Koroskin
On Wed, 21 Oct 2009 20:15:16 +0400, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: Today, structs can't write their own this(). There aren't very solid reasons for that except that it makes language implementation more difficult. I wonder how much of a problem that could be in

Re: this() not executing code on structs

2009-10-21 Thread Bartosz Milewski
Andrei Alexandrescu Wrote: this() { myCount = count++; } // ERROR It's worse than that. Try this: struct foo { this(int dummy = 0) { writeln(Default constructor);} } foo x = foo(); Nothing gets printed. If default constructors are disallowed, so should constructors with all

Re: this() not executing code on structs

2009-10-21 Thread Bartosz Milewski
This means that no non-trivial invariant may be defined for a struct. In most cases it doesn't matter, but it might be a problem with the smart pointer family. For instance, refcounted may not assume that the shared refcount pointer has been allocated. Without this invariant all refcounted

Re: this() not executing code on structs

2009-10-21 Thread Leandro Lucarella
Bartosz Milewski, el 21 de octubre a las 16:33 me escribiste: Andrei Alexandrescu Wrote: this() { myCount = count++; } // ERROR It's worse than that. Try this: struct foo { this(int dummy = 0) { writeln(Default constructor);} } foo x = foo(); Nothing gets

Re: this() not executing code on structs

2009-10-21 Thread Rainer Deyke
Andrei Alexandrescu wrote: Today, structs can't write their own this(). There aren't very solid reasons for that except that it makes language implementation more difficult. I wonder how much of a problem that could be in practice. I realized today that the Counted example - a classic C++

Re: this() not executing code on structs

2009-10-21 Thread grauzone
Andrei Alexandrescu wrote: Today, structs can't write their own this(). There aren't very solid reasons for that except that it makes language implementation more difficult. I wonder how much of a problem that could be in practice. I realized today that the Counted example - a classic C++

Re: this() not executing code on structs

2009-10-21 Thread Steven Schveighoffer
On Wed, 21 Oct 2009 17:54:08 -0400, grauzone n...@example.net wrote: I'd really like to know why scope x = new X(); is unsafe, while encouraging doing exactly the same with structs seems to be a perfectly fine idea. Allocating structs on the stack is obviously not any safer than with