Re: Explicit default constructor for structs

2014-04-27 Thread Temtaime via Digitalmars-d
People, why you hates ctors for structs ? Default ctor - simple a workaround. Just allow ctors with structs and it's all.

Re: Explicit default constructor for structs

2014-04-27 Thread deadalnix via Digitalmars-d
On Thursday, 10 April 2014 at 11:13:45 UTC, monarch_dodra wrote: Or a named function: auto foo = foo(); Or a make template: auto foo = make!Foo(); Or a dummy argument: auto foo = Foo(Foo.dummy); Or ditto with a global dummy: auto foo = Foo(dummyArg); Or use a static opCall:auto foo =

Re: Explicit default constructor for structs

2014-04-26 Thread ketmar via Digitalmars-d
On Wednesday, 9 April 2014 at 14:59:35 UTC, Benjamin Thaut wrote: E.g. it could look like this (alternative a new keyword explicit could be introduced, but introduction of new keywords is usually avoided if possible, AFAIK): sorry for not reading the whole post and necroposting, but please,

Re: Explicit default constructor for structs

2014-04-12 Thread Jacob Carlborg
On 2014-04-11 22:48, monarch_dodra wrote: Right, the call will succeed, but if the function accesses any class members, it will access violation *there*. Hence the highly likely. Yeah, right. -- /Jacob Carlborg

Re: Explicit default constructor for structs

2014-04-11 Thread Daniel Murphy
monarch_dodra wrote in message news:rftskgfoeuvyeuvru...@forum.dlang.org... *BUT*, if you happen to copy paste C++ code, and it *does* compile, then it is pretty much expected to keep the same resulting semantics, yes. These expectations will lead to disappointment.

Re: Explicit default constructor for structs

2014-04-11 Thread Dicebot
On Thursday, 10 April 2014 at 21:23:43 UTC, monarch_dodra wrote: *BUT*, if you happen to copy paste C++ code, and it *does* compile, then it is pretty much expected to keep the same resulting semantics, yes. It does not work that way and has never worked. Think about class semantics for

Re: Explicit default constructor for structs

2014-04-11 Thread monarch_dodra
On Friday, 11 April 2014 at 12:58:09 UTC, Dicebot wrote: On Thursday, 10 April 2014 at 21:23:43 UTC, monarch_dodra wrote: *BUT*, if you happen to copy paste C++ code, and it *does* compile, then it is pretty much expected to keep the same resulting semantics, yes. It does not work that way

Re: Explicit default constructor for structs

2014-04-11 Thread Jonathan M Davis
On Friday, April 11, 2014 22:38:28 Daniel Murphy wrote: monarch_dodra wrote in message news:rftskgfoeuvyeuvru...@forum.dlang.org... *BUT*, if you happen to copy paste C++ code, and it *does* compile, then it is pretty much expected to keep the same resulting semantics, yes. These

Re: Explicit default constructor for structs

2014-04-11 Thread Jacob Carlborg
On 2014-04-11 15:53, monarch_dodra wrote: Yeah. It'd say those wouldn't compile anyway, but I guess something as trivial as: // class A {...} A a; a.doit; // Would compile for both languages, but give different results. Fine. Unless doit is non-virtual in both versions. -- /Jacob

Re: Explicit default constructor for structs

2014-04-11 Thread monarch_dodra
On Friday, 11 April 2014 at 15:54:36 UTC, Jacob Carlborg wrote: On 2014-04-11 15:53, monarch_dodra wrote: Yeah. It'd say those wouldn't compile anyway, but I guess something as trivial as: // class A {...} A a; a.doit; // Would compile for both languages, but give different results.

Re: Explicit default constructor for structs

2014-04-11 Thread Daniel Murphy
monarch_dodra wrote in message news:ktbdlcaqahsqmwkid...@forum.dlang.org... Why? The D version would just go from object.Error Access Violation to AssertError null this. And in release, you'd still (highly probably) still get the Access Violation. Sadly I've encountered C++ code that

Re: Explicit default constructor for structs

2014-04-11 Thread Remo
On Friday, 11 April 2014 at 12:38:14 UTC, Daniel Murphy wrote: monarch_dodra wrote in message news:rftskgfoeuvyeuvru...@forum.dlang.org... *BUT*, if you happen to copy paste C++ code, and it *does* compile, then it is pretty much expected to keep the same resulting semantics, yes. These

Re: Explicit default constructor for structs

2014-04-11 Thread Jonathan M Davis
On Friday, April 11, 2014 17:00:50 Remo wrote: On Friday, 11 April 2014 at 12:38:14 UTC, Daniel Murphy wrote: monarch_dodra wrote in message news:rftskgfoeuvyeuvru...@forum.dlang.org... *BUT*, if you happen to copy paste C++ code, and it *does* compile, then it is pretty much expected

Re: Explicit default constructor for structs

2014-04-11 Thread Jacob Carlborg
On 2014-04-11 18:05, monarch_dodra wrote: Why? The D version would just go from object.Error Access Violation to AssertError null this. Hmm, I was pretty sure it wouldn't assert. And in release, you'd still (highly probably) still get the Access Violation. No, in release mode it's

Re: Explicit default constructor for structs

2014-04-11 Thread monarch_dodra
On Friday, 11 April 2014 at 20:36:12 UTC, Jacob Carlborg wrote: On 2014-04-11 18:05, monarch_dodra wrote: Why? The D version would just go from object.Error Access Violation to AssertError null this. Hmm, I was pretty sure it wouldn't assert. And in release, you'd still (highly probably)

Re: Explicit default constructor for structs

2014-04-11 Thread Jonathan M Davis
On Saturday, April 12, 2014 02:26:54 Daniel Murphy wrote: monarch_dodra wrote in message news:ktbdlcaqahsqmwkid...@forum.dlang.org... Why? The D version would just go from object.Error Access Violation to AssertError null this. And in release, you'd still (highly probably) still get

Re: Explicit default constructor for structs

2014-04-10 Thread monarch_dodra
On Wednesday, 9 April 2014 at 18:41:57 UTC, Walter Bright wrote: On 4/9/2014 7:59 AM, Benjamin Thaut wrote: What do you think? CC welcome. Or you could use a factory function: struct Foo { static Foo factory() { ... } ... } auto foo = Foo.factory(); Yeah. For sure. Or a

Re: Explicit default constructor for structs

2014-04-10 Thread Andrej Mitrovic
On 4/9/14, Brian Schott briancsch...@gmail.com wrote: Really? What does this program print using a current version of DMD? import std.stdio; struct SomeStruct { this(int i = 10) { this.i = i; } int i; } void main(string[] args) { auto s

Re: Explicit default constructor for structs

2014-04-10 Thread Remo
On Thursday, 10 April 2014 at 11:39:16 UTC, Andrej Mitrovic wrote: On 4/9/14, Brian Schott briancsch...@gmail.com wrote: Really? What does this program print using a current version of DMD? import std.stdio; struct SomeStruct { this(int i = 10) { this.i = i;

Re: Explicit default constructor for structs

2014-04-10 Thread Atila Neves
+1 Atila Yeah. For sure. Or a named function: auto foo = foo(); Or a make template: auto foo = make!Foo(); Or a dummy argument: auto foo = Foo(Foo.dummy); Or ditto with a global dummy: auto foo = Foo(dummyArg); Or use a static opCall:auto foo = Foo(); Or use an initialize function:

Re: Explicit default constructor for structs

2014-04-10 Thread Jacob Carlborg
On 2014-04-10 17:21, Remo wrote: Please do not forget about C++ porting problems that are related to this. The code from C++ should compile and work as expected or does not compile at all and give meaningful error message. Right now it compiles but does not work at all. This struct constructor

Re: Explicit default constructor for structs

2014-04-10 Thread monarch_dodra
On Thursday, 10 April 2014 at 19:28:16 UTC, Jacob Carlborg wrote: On 2014-04-10 17:21, Remo wrote: Please do not forget about C++ porting problems that are related to this. The code from C++ should compile and work as expected or does not compile at all and give meaningful error message.

Explicit default constructor for structs

2014-04-09 Thread Benjamin Thaut
Just to be clear, I don't want a default constructor for structs that gets called implictly by the compiler, like in C++. Instead I would really love to have a explicit default constructor. E.g. it could look like this (alternative a new keyword explicit could be introduced, but introduction

Re: Explicit default constructor for structs

2014-04-09 Thread John Colvin
On Wednesday, 9 April 2014 at 14:59:35 UTC, Benjamin Thaut wrote: Just to be clear, I don't want a default constructor for structs that gets called implictly by the compiler, like in C++. Instead I would really love to have a explicit default constructor. E.g. it could look like this

Re: Explicit default constructor for structs

2014-04-09 Thread monarch_dodra
On Wednesday, 9 April 2014 at 14:59:35 UTC, Benjamin Thaut wrote: What do you think? CC welcome. Kind Regards Benjamin Thaut I haven't read though the entire proposal yet (sorry!), but I'm in definite agreement that *something* needs to be done to allow explicit but argument-less

Re: Explicit default constructor for structs

2014-04-09 Thread Brian Schott
What would this do? struct SomeStruct { this(int i = 10) { this.i = i; } this(void) { this.i = 20; } int i; } auto s = SomeStruct();

Re: Explicit default constructor for structs

2014-04-09 Thread Jacob Carlborg
On 2014-04-09 16:59, Benjamin Thaut wrote: Just to be clear, I don't want a default constructor for structs that gets called implictly by the compiler, like in C++. Instead I would really love to have a explicit default constructor. E.g. it could look like this (alternative a new keyword

Re: Explicit default constructor for structs

2014-04-09 Thread Brian Schott
On Wednesday, 9 April 2014 at 17:07:13 UTC, Jacob Carlborg wrote: Result in an ambiguity error? Really? What does this program print using a current version of DMD? import std.stdio; struct SomeStruct { this(int i = 10) { this.i = i; } int i;

Re: Explicit default constructor for structs

2014-04-09 Thread Jacob Carlborg
On 2014-04-09 18:59, Brian Schott wrote: What would this do? struct SomeStruct { this(int i = 10) { this.i = i; } this(void) { this.i = 20; } int i; } auto s = SomeStruct(); Result in an ambiguity error? -- /Jacob Carlborg

Re: Explicit default constructor for structs

2014-04-09 Thread Timon Gehr
On 04/09/2014 04:59 PM, Benjamin Thaut wrote: Instead I would really love to have a explicit default constructor. E.g. it could look like this (alternative a new keyword explicit could be introduced, but introduction of new keywords is usually avoided if possible, AFAIK): struct Foo {

Re: Explicit default constructor for structs

2014-04-09 Thread Walter Bright
On 4/9/2014 7:59 AM, Benjamin Thaut wrote: What do you think? CC welcome. Or you could use a factory function: struct Foo { static Foo factory() { ... } ... } auto foo = Foo.factory();

Re: Explicit default constructor for structs

2014-04-09 Thread Benjamin Thaut
Am 09.04.2014 18:59, schrieb Brian Schott: What would this do? struct SomeStruct { this(int i = 10) { this.i = i; } this(void) { this.i = 20; } int i; } auto s = SomeStruct(); Thats easy to answer. What would it do if you replace the

Re: Explicit default constructor for structs

2014-04-09 Thread Benjamin Thaut
Am 09.04.2014 19:05, schrieb Jacob Carlborg: What's the advantage over using a static opCall, that it works with new? That you can use it together with @disable this();

Re: Explicit default constructor for structs

2014-04-09 Thread Benjamin Thaut
Am 09.04.2014 20:42, schrieb Walter Bright: On 4/9/2014 7:59 AM, Benjamin Thaut wrote: What do you think? CC welcome. Or you could use a factory function: struct Foo { static Foo factory() { ... } ... } auto foo = Foo.factory(); But I don't want the construction to

Re: Explicit default constructor for structs

2014-04-09 Thread Brian Schott
On Wednesday, 9 April 2014 at 18:47:41 UTC, Benjamin Thaut wrote: Thats easy to answer. What would it do if you replace the struct with class and the void with nothing? This thread is giving me some fun ideas for static analysis rules.

Re: Explicit default constructor for structs

2014-04-09 Thread Benjamin Thaut
Am 09.04.2014 20:53, schrieb Brian Schott: On Wednesday, 9 April 2014 at 18:47:41 UTC, Benjamin Thaut wrote: Thats easy to answer. What would it do if you replace the struct with class and the void with nothing? This thread is giving me some fun ideas for static analysis rules. Just saying,

Re: Explicit default constructor for structs

2014-04-09 Thread Benjamin Thaut
Am 09.04.2014 20:33, schrieb Timon Gehr: On 04/09/2014 04:59 PM, Benjamin Thaut wrote: Why not just: struct Foo{ this(){ // do stuff here } } void main(){ Foo foo1; // error, no init value auto foo2=Foo(); // ok } Because then the user might think, that the

Re: Explicit default constructor for structs

2014-04-09 Thread Timon Gehr
On 04/09/2014 08:53 PM, Benjamin Thaut wrote: Am 09.04.2014 20:33, schrieb Timon Gehr: On 04/09/2014 04:59 PM, Benjamin Thaut wrote: Why not just: struct Foo{ this(){ // do stuff here } } void main(){ Foo foo1; // error, no init value auto foo2=Foo(); // ok }

Re: Explicit default constructor for structs

2014-04-09 Thread Brian Schott
On Wednesday, 9 April 2014 at 18:53:20 UTC, Brian Schott wrote: On Wednesday, 9 April 2014 at 18:47:41 UTC, Benjamin Thaut wrote: Thats easy to answer. What would it do if you replace the struct with class and the void with nothing? This thread is giving me some fun ideas for static analysis

Re: Explicit default constructor for structs

2014-04-09 Thread Benjamin Thaut
Am 09.04.2014 21:02, schrieb Timon Gehr: On 04/09/2014 08:53 PM, Benjamin Thaut wrote: Am 09.04.2014 20:33, schrieb Timon Gehr: On 04/09/2014 04:59 PM, Benjamin Thaut wrote: Why not just: struct Foo{ this(){ // do stuff here } } void main(){ Foo foo1; // error, no

Re: Explicit default constructor for structs

2014-04-09 Thread Jacob Carlborg
On 2014-04-09 19:10, Brian Schott wrote: Really? What does this program print using a current version of DMD? import std.stdio; struct SomeStruct { this(int i = 10) { this.i = i; } int i; } void main(string[] args) { auto s = SomeStruct(); writeln(s.i =