Constructors (starstruck noob from C++)

2011-01-20 Thread Luke J. West
Hi to all from a total noob. first of all, I'd like to say how impressed I am with D. In fact, I keep pinching myself. Have I *really* found a language worth leaving C++ for after two decades? It's beginning to look that way. Obviously I'm devouring the 2.0 documentation right now, but have not ye

Re: Constructors (starstruck noob from C++)

2011-01-20 Thread Ellery Newcomer
Welcome! On 01/20/2011 07:18 PM, Luke J. West wrote: how do I, in c++ speak, do the D for... A b(a); // or if you prefer... A* b = new A(a); try A b = new A(a); I'm sure this must be trivial. Many many thanks, Luke

Re: Constructors (starstruck noob from C++)

2011-01-20 Thread Jonathan M Davis
On Thursday, January 20, 2011 17:18:48 Luke J. West wrote: > Hi to all from a total noob. > > first of all, I'd like to say how impressed I am with D. In fact, I keep > pinching myself. Have I *really* found a language worth leaving C++ for > after two decades? It's beginning to look that way. Obv

Re: Constructors (starstruck noob from C++)

2011-01-20 Thread Andrei Alexandrescu
On 1/20/11 7:18 PM, Luke J. West wrote: Hi to all from a total noob. first of all, I'd like to say how impressed I am with D. In fact, I keep pinching myself. Have I *really* found a language worth leaving C++ for after two decades? It's beginning to look that way. Obviously I'm devouring the 2.

Re: Constructors (starstruck noob from C++)

2011-01-20 Thread Andrej Mitrovic
Be afraid.. be very afraid! import std.algorithm; import std.stdio; import std.conv; enum fields = [__traits(allMembers, Foo)]; string populateFields(string[] haystack) { string result; while (haystack.length > 0) { switch (haystack[0]) { case "__ctor":

Re: Constructors (starstruck noob from C++)

2011-01-20 Thread Andrej Mitrovic
Ah, damnit, Andrei beat me to the punch! Well, at least his methods make much more sense than my little hacks.

Re: Constructors (starstruck noob from C++)

2011-01-20 Thread Andrej Mitrovic
On 1/21/11, Andrei Alexandrescu wrote: > I think copyMembers belongs to the standard library. I wanted to define > a family of functions like it but never got around to it. > It's a shame we can't use .dup. It would look really nice in code.

Re: Constructors (starstruck noob from C++)

2011-01-20 Thread Robert Jacques
On Thu, 20 Jan 2011 22:02:42 -0500, Andrei Alexandrescu wrote: On 1/20/11 7:18 PM, Luke J. West wrote: Hi to all from a total noob. first of all, I'd like to say how impressed I am with D. In fact, I keep pinching myself. Have I *really* found a language worth leaving C++ for after two deca

Re: Constructors (starstruck noob from C++)

2011-01-21 Thread Jacob Carlborg
On 2011-01-21 04:02, Andrei Alexandrescu wrote: On 1/20/11 7:18 PM, Luke J. West wrote: Hi to all from a total noob. first of all, I'd like to say how impressed I am with D. In fact, I keep pinching myself. Have I *really* found a language worth leaving C++ for after two decades? It's beginning

Re: Constructors (starstruck noob from C++)

2011-01-21 Thread Andrei Alexandrescu
On 1/20/11 11:28 PM, Robert Jacques wrote: On Thu, 20 Jan 2011 22:02:42 -0500, Andrei Alexandrescu wrote: First, why not use tupleof? b.tupleof = a.tupleof; works perfectly fine, simpler and ahem, actually works. __traits(getMember, ...) has to obey scoping rules, so using it with a class that d

Re: Constructors (starstruck noob from C++)

2011-01-21 Thread spir
On 01/21/2011 04:48 AM, Andrej Mitrovic wrote: On 1/21/11, Andrei Alexandrescu wrote: I think copyMembers belongs to the standard library. I wanted to define a family of functions like it but never got around to it. It's a shame we can't use .dup. It would look really nice in code. +++ De

Re: Constructors (starstruck noob from C++)

2011-01-21 Thread bearophile
spir: > > It's a shame we can't use .dup. It would look really nice in code. > > +++ Copying classes is not a so common need in D. As an example, I need a byPair() method for AAs more than dup for classes :-) Bye, bearophile

Re: Constructors (starstruck noob from C++)

2011-01-21 Thread spir
On 01/21/2011 06:28 AM, Robert Jacques wrote: void copyMembers(A)(A src, A tgt) if (is(A == class)) { tgt.tupleof = src.tupleof; } What about this feature in Object under name "copy" or "dup"? Sure, it's not to be used evereday; but it's typcally the kind of routine that, when needed, we're v

Re: Constructors (starstruck noob from C++)

2011-01-21 Thread spir
On 01/21/2011 01:29 PM, bearophile wrote: > spir: > >>> It's a shame we can't use .dup. It would look really nice in code. >> >> +++ > > Copying classes is not a so common need in D. As an example, I need a byPair() method for AAs more than dup for classes :-) > > Bye, > bearophile Sure, but wh

Re: Constructors (starstruck noob from C++)

2011-01-21 Thread Andrej Mitrovic
Theorizing: Would it be a bad idea if .dup for classes did the same thing as normal assignment did for structs with postblit constructors? Essentially I was thinking that code like this would do the trick: import std.stdio; class Widget { int integral; // field-by-field assignment int[]

Re: Constructors (starstruck noob from C++)

2011-01-21 Thread Robert Jacques
On Fri, 21 Jan 2011 08:16:24 -0500, spir wrote: On 01/21/2011 06:28 AM, Robert Jacques wrote: void copyMembers(A)(A src, A tgt) if (is(A == class)) { tgt.tupleof = src.tupleof; } What about this feature in Object under name "copy" or "dup"? Sure, it's not to be used evereday; but it's typc

Re: Constructors (starstruck noob from C++)

2011-01-21 Thread spir
On 01/21/2011 05:27 PM, Robert Jacques wrote: On Fri, 21 Jan 2011 08:16:24 -0500, spir wrote: On 01/21/2011 06:28 AM, Robert Jacques wrote: void copyMembers(A)(A src, A tgt) if (is(A == class)) { tgt.tupleof = src.tupleof; } What about this feature in Object under name "copy" or "dup"? Sure

Re: Constructors (starstruck noob from C++)

2011-01-21 Thread Steven Schveighoffer
On Fri, 21 Jan 2011 14:54:53 -0500, spir wrote: On 01/21/2011 05:27 PM, Robert Jacques wrote: On Fri, 21 Jan 2011 08:16:24 -0500, spir wrote: On 01/21/2011 06:28 AM, Robert Jacques wrote: void copyMembers(A)(A src, A tgt) if (is(A == class)) { tgt.tupleof = src.tupleof; } What about this

Re: Constructors (starstruck noob from C++)

2011-01-21 Thread Jonathan M Davis
On Friday, January 21, 2011 12:10:26 Steven Schveighoffer wrote: > On Fri, 21 Jan 2011 14:54:53 -0500, spir wrote: > > (*) > > Or do people really speak like: > > << Would you please make a duplicate of the guest list? >> > > in the US? > > They might, it doesn't sound that odd to me, though copy