Re: inheriting ctors?

2010-08-06 Thread Rory Mcguire
Sean Kelly wrote: > Steven Schveighoffer Wrote: > >> On Thu, 05 Aug 2010 13:53:20 -0400, dcoder wrote: >> >> > Suppose I have a base class with many ctors(). >> > >> > I want to inherit from the base class and make one slight alteration to >> > it, >> > but I don't want to write X times the fol

Isn't __traits part of the language?

2010-08-06 Thread simendsjo
Rationale (http://digitalmars.com/d/2.0/rationale.html) says: """Why not use operator names like __add__ and __div__ instead of opAdd, opDiv, etc.? __ keywords should indicate a proprietary language extension, not a basic part of the language. """ But traits is explained under the language

ref is pointer sugar?

2010-08-06 Thread Pluto
Are these equivalent? S s;//struct void f(ref S s){s.x++;} f(s); void f2(S* s){(*s).x++;} f2(&s); If so, why is it stated that ref is very rarely used? It looks like something I would use a lot with structures.

Re: Isn't __traits part of the language?

2010-08-06 Thread Steven Schveighoffer
On Fri, 06 Aug 2010 08:42:40 -0400, simendsjo wrote: Rationale (http://digitalmars.com/d/2.0/rationale.html) says: """Why not use operator names like __add__ and __div__ instead of opAdd, opDiv, etc.? __ keywords should indicate a proprietary language extension, not a basic part of the

Re: ref is pointer sugar?

2010-08-06 Thread Steven Schveighoffer
On Fri, 06 Aug 2010 08:51:31 -0400, Pluto wrote: Are these equivalent? S s;//struct void f(ref S s){s.x++;} f(s); void f2(S* s){(*s).x++;} f2(&s); They are pretty much equivalent. I think the code generated actually will be exactly the same. However, the compiler treats ref differently

Re: ref is pointer sugar?

2010-08-06 Thread Pluto
== Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article > On Fri, 06 Aug 2010 08:51:31 -0400, Pluto wrote: > > Are these equivalent? > > > > S s;//struct > > > > void f(ref S s){s.x++;} > > f(s); > > > > void f2(S* s){(*s).x++;} > > f2(&s); > They are pretty much equivalent. I think th

Do I have to cast double to cdouble everywhere?

2010-08-06 Thread John Travers
Hi, I'm investigating if D would be useful to me as a numerical programming language to replace my current mix of fortran and python. I'm stuck with a problem which seems odd to me: cdouble c1; c1 = 2.0; complains: Error: cannot implicitly convert expression (2) of type double to c

Re: ref is pointer sugar?

2010-08-06 Thread Pluto
== Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article > On Fri, 06 Aug 2010 08:51:31 -0400, Pluto wrote: > > Are these equivalent? > > > > S s;//struct > > > > void f(ref S s){s.x++;} > > f(s); > > > > void f2(S* s){(*s).x++;} > > f2(&s); > They are pretty much equivalent. I think th

Re: Do I have to cast double to cdouble everywhere?

2010-08-06 Thread bearophile
John Travers: > c1 = cast(cdouble)2.0; Casts are bad, better to avoid them when possible. You can do this: void main() { cdouble c1; c1 = 2.0 + 0i; } But complex numbers will be removed from D, they will become partially library ones (imaginary ones will probably just removed). I think

Re: ref is pointer sugar?

2010-08-06 Thread Jacob Carlborg
On 2010-08-06 15:33, Pluto wrote: == Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article On Fri, 06 Aug 2010 08:51:31 -0400, Pluto wrote: Are these equivalent? S s;//struct void f(ref S s){s.x++;} f(s); void f2(S* s){(*s).x++;} f2(&s); They are pretty much equivalent. I think

Re: inheriting ctors?

2010-08-06 Thread Philippe Sigaud
On Fri, Aug 6, 2010 at 11:43, Rory Mcguire wrote: > I've been trying to make a template for this but it seems that dmd still > won't allow me to get the parameters of the constructors. dmd Seems to > think > that I'm trying to use it as a property. > > > void main() { >foreach (m; __traits(

Re: inheriting ctors?

2010-08-06 Thread bearophile
Philippe Sigaud: > This is my new once-a-day bug :( Add them all to Bugzilla :-) Bye, bearophile

Re: inheriting ctors?

2010-08-06 Thread Philippe Sigaud
On Fri, Aug 6, 2010 at 19:09, bearophile wrote: > Philippe Sigaud: > > This is my new once-a-day bug :( > > Add them all to Bugzilla :-) > I do, from time to time. But I'm never sure if it's a bug or not. It's related to The Great And Neverending Property Debate (tm). So I don't what to believe

Re: inheriting ctors?

2010-08-06 Thread Rory Mcguire
Philippe Sigaud wrote: > On Fri, Aug 6, 2010 at 11:43, Rory Mcguire > wrote: > > >> I've been trying to make a template for this but it seems that dmd still >> won't allow me to get the parameters of the constructors. dmd Seems to >> think >> that I'm trying to use it as a property. >> >> > >>

Re: ref is pointer sugar?

2010-08-06 Thread Pluto
== Quote from Jacob Carlborg (d...@me.com)'s article > On 2010-08-06 15:33, Pluto wrote: > > == Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article > >> On Fri, 06 Aug 2010 08:51:31 -0400, Pluto wrote: > >>> Are these equivalent? > >>> > >>> S s;//struct > >>> > >>> void f(ref S s){s.x

Re: inheriting ctors?

2010-08-06 Thread Rory Mcguire
Rory Mcguire wrote: > Philippe Sigaud wrote: > >> On Fri, Aug 6, 2010 at 11:43, Rory Mcguire >> wrote: >> >> >>> I've been trying to make a template for this but it seems that dmd still >>> won't allow me to get the parameters of the constructors. dmd Seems to >>> think >>> that I'm trying to

Operator overloading problem

2010-08-06 Thread Blonder
Hello, can someone help me with this? struct Group { int i1; Group opBinary(string op)(int x) { // do somehting return this; } Group opBinary(string op)(Group g) { // do something return this; } } Group g, h; g.i1 = 1; h = g+g;

Re: Operator overloading problem

2010-08-06 Thread Jonathan M Davis
On Friday, August 06, 2010 12:30:38 Blonder wrote: > Hello, > > can someone help me with this? > > struct Group { > int i1; > Group opBinary(string op)(int x) { > // do somehting > return this; > } > Group opBinary(string op)(Group g) { > // do something >

Re: inheriting ctors?

2010-08-06 Thread Rory Mcguire
dcoder wrote: > Suppose I have a base class with many ctors(). > > I want to inherit from the base class and make one slight alteration to > it, but I don't want to write X times the following: > > this(args) { > super(args); > } > > Does D have an easy way for the derived class to 'inherit'

Re: Operator overloading problem

2010-08-06 Thread Blonder
Hello, I am trying to understand how operator overloading works with D. I am a C++ programmer and I am reading the book of Andrei Alexandrescu and try to understand D and it's language features. My Group example don't compile, the error is: Error: template instance opBinary!("+") matches more th

Re: Operator overloading problem

2010-08-06 Thread div0
On 06/08/2010 21:08, Blonder wrote: Hello, I am trying to understand how operator overloading works with D. I am a C++ programmer and I am reading the book of Andrei Alexandrescu and try to understand D and it's language features. My Group example don't compile, the error is: Error: template i

Re: Operator overloading problem

2010-08-06 Thread div0
On 06/08/2010 21:37, div0 wrote: You need to add a second template parameter for the function arguments and add a template constrait like so: struct Group { int i1; Group opBinary(string op, U) (U x) if(op == "+" && is(U: int)) { // do somehting return this;

Re: inheriting ctors?

2010-08-06 Thread Philippe Sigaud
On Fri, Aug 6, 2010 at 21:59, Rory Mcguire wrote: > > Here is a possible solution to your problem: > > -Rory I believe you can get the type of A. Isn't it typeof(super) or std.traits.BaseClassesTuple!B[0] ? B in the latter case being typeof(this) That way, there is no need for the user to provi

Re: Operator overloading problem

2010-08-06 Thread Philippe Sigaud
On Fri, Aug 6, 2010 at 22:37, div0 wrote: > Personally, I'm with you and I would expect that the compiler should > example the function parameters after the template string parameter but it > doesn't. > Yes :o( You need to add a second template parameter for the function arguments and add a temp

Re: Operator overloading problem

2010-08-06 Thread Blonder
Hello, this seems to work, but if I add the following double opBinary(string op, U) (U rhs) { static if(op == "^" && is(U: Group)) { // do something return 42; } } because I wa

Re: Operator overloading problem

2010-08-06 Thread div0
On 06/08/2010 22:24, Blonder wrote: Hello, this seems to work, but if I add the following double opBinary(string op, U) (U rhs) { static if(op == "^"&& is(U: Group)) { // do something return 42;

Re: inheriting ctors?

2010-08-06 Thread Andrej Mitrovic
There is an AutoImplement class template in http://www.digitalmars.com/d/2.0/phobos/std_typecons.html#AutoImplement , which I've just been trying out. Apparently you can pass it 1: a Base class, 2: a templated function to filter out which functions you want to inherit/overwrite from the Base cl

Re: Operator overloading problem

2010-08-06 Thread Blonder
Thanks, that is the solution. > No programming language is intuitive; they all take time to learn. > D is a big win over C++ though and well worth sticking with. Yes, you are right, it takes time to learn. @Philippe Sigaud Thanks also.

Re: inheriting ctors?

2010-08-06 Thread Andrej Mitrovic
Here's an example: import std.stdio; import std.traits; import std.conv; import std.typecons; class C { int m_value; int testMe() { return 1; } this(int x) { m_value = x; } this(int x, int z) { m_value = x + z; } }