wchar[] and wchar*

2009-04-06 Thread novice2
hi! could you advice me, please, what techniques should be used while working with D wchar[] and C wchar* (e.g. Windows unicode API named ...W()). how to pass wchar[] to FuncW(wchar*) and back? thanks!

Re: cast a LinkSeq

2009-04-06 Thread Daniel Keep
Qian Xu wrote: > Adam Burton wrote: >> I wouldn't think so, cos LinkSeq!(Apple) does not inherit >> LinkSeq!(Fruit), they are 2 separate types. However your apples >> automatically downcast (or up, depending which way you like to draw >> your diagrams :-) ) so unless you intend to pass the LinkS

Re: Factoring out looping structure

2009-04-06 Thread Doctor J
Thank you for your prompt replies, that helps a lot. I'll combine both ideas so I can keep the functions for one variant together. Much appreciated.

Re: Factoring out looping structure

2009-04-06 Thread Denis Koroskin
On Tue, 07 Apr 2009 00:33:04 +0400, Doctor J wrote: I'm new to template programming and I have a problem for which I think it would be a good match, but I'd like to get some advice on how to go about it. I have a family of algorithms with the same looping structure, but different particu

Re: Factoring out looping structure

2009-04-06 Thread BCS
Reply to Doctor, I'm new to template programming and I have a problem for which I think it would be a good match, but I'd like to get some advice on how to go about it. I have a family of algorithms with the same looping structure, but different particulars: state_t st

Factoring out looping structure

2009-04-06 Thread Doctor J
I'm new to template programming and I have a problem for which I think it would be a good match, but I'd like to get some advice on how to go about it. I have a family of algorithms with the same looping structure, but different particulars: state_t state ; for (int i =

Re: Wht std.complex is needed?

2009-04-06 Thread Don
Steven Schveighoffer wrote: On Mon, 06 Apr 2009 09:50:35 -0400, Don wrote: Steven Schveighoffer wrote: On Mon, 06 Apr 2009 08:36:18 -0400, Don wrote: Sam Hu wrote: Thank you! Anothe silly question then:What's the disadvantage to have the built-in type of i-type? Regards, Sam It's a v

Re: cast a LinkSeq

2009-04-06 Thread Qian Xu
Adam Burton wrote: I wouldn't think so, cos LinkSeq!(Apple) does not inherit LinkSeq!(Fruit), they are 2 separate types. However your apples automatically downcast (or up, depending which way you like to draw your diagrams :-) ) so unless you intend to pass the LinkSeq!(Apple) into a function

Re: cast a LinkSeq

2009-04-06 Thread Adam Burton
I wouldn't think so, cos LinkSeq!(Apple) does not inherit LinkSeq!(Fruit), they are 2 separate types. However your apples automatically downcast (or up, depending which way you like to draw your diagrams :-) ) so unless you intend to pass the LinkSeq!(Apple) into a function expecting LinkSeq!(F

Re: Wht std.complex is needed?

2009-04-06 Thread Joel C. Salomon
bearophile wrote: > A better question can be: "What's the advantage of having a built-in > imaginary type?" :-) > You can find an answer here, from page 11: > http://www.eecs.berkeley.edu/~wkahan/JAVAhurt.pdf > But maybe those ideas aren't much true anymore today. Why could you not make a struct

cast a LinkSeq

2009-04-06 Thread Qian Xu
Hi All, can I cast a LinkSeq from inherited type to base type? code -- class Fruit {} class Apple: Fruit {} auto apples = new LinkSeq!(Apple); apples.append(new Apple); assert(apples !is null); assert(apples.length == 1);

Re: Wht std.complex is needed?

2009-04-06 Thread Steven Schveighoffer
On Mon, 06 Apr 2009 09:50:35 -0400, Don wrote: Steven Schveighoffer wrote: On Mon, 06 Apr 2009 08:36:18 -0400, Don wrote: Sam Hu wrote: Thank you! Anothe silly question then:What's the disadvantage to have the built-in type of i-type? Regards, Sam It's a very nasty type. It supports

Re: Wht std.complex is needed?

2009-04-06 Thread Don
Steven Schveighoffer wrote: On Mon, 06 Apr 2009 08:36:18 -0400, Don wrote: Sam Hu wrote: Thank you! Anothe silly question then:What's the disadvantage to have the built-in type of i-type? Regards, Sam It's a very nasty type. It supports *, but isn't closed under *. Which is really annoyi

Re: Wht std.complex is needed?

2009-04-06 Thread Daniel Keep
Steven Schveighoffer wrote: > On Mon, 06 Apr 2009 08:36:18 -0400, Don wrote: > >> Sam Hu wrote: >>> Thank you! >>> Anothe silly question then:What's the disadvantage to have the >>> built-in type of i-type? >>> Regards, >>> Sam >> >> It's a very nasty type. It supports *, but isn't closed unde

Bit operator conversions

2009-04-06 Thread Kagamin
Is it valid for this to compile: --- ushort a(ushort b) pure nothrow { return b<<10|b; } --- And for this to not compile: --- ushort a(ushort b) pure nothrow { return b<<10; } --- ?

Re: Wht std.complex is needed?

2009-04-06 Thread Steven Schveighoffer
On Mon, 06 Apr 2009 08:36:18 -0400, Don wrote: Sam Hu wrote: Thank you! Anothe silly question then:What's the disadvantage to have the built-in type of i-type? Regards, Sam It's a very nasty type. It supports *, but isn't closed under *. Which is really annoying for generic programming.

Re: minimal evaluation

2009-04-06 Thread Qian Xu
torhu wrote: > > If you mean short-circuit evalutation, I'm pretty sure that's always > what the compiler does. Thanks. Somebody posted this link: http://digitalmars.com/d/1.0/expression.html#OrOrExpression

Re: Wht std.complex is needed?

2009-04-06 Thread Don
Sam Hu wrote: Thank you! Anothe silly question then:What's the disadvantage to have the built-in type of i-type? Regards, Sam It's a very nasty type. It supports *, but isn't closed under *. Which is really annoying for generic programming. idouble x = 2i; x *= x; // oops, this isn't imagina

Re: minimal evaluation

2009-04-06 Thread torhu
On 06.04.2009 13:30, Qian Xu wrote: Hi All, Is minimal evaluation always enabled in D? I want to write a function IsNull(), so that I can check the precondition as follows: if (isNull(foo) || isNull(foo.getBar) || isNull(foo.getBar.getBar2) { return false; } // n

Re: Format.convert problme

2009-04-06 Thread Qian Xu
grauzone wrote: > mport tango.io.Stdout; > > void main() { > > int v = 55; > int *pv = &v; > > //pv (an int pointer) can be exchanged with v (an int), > //and it still works > auto i = pv; > > alias typeof(i) T; > static if (is(T T2 : T2*)) { > T2 i2 = *i; > Stdout.formatln("{}", i2); > } else

Re: minimal evaluation

2009-04-06 Thread Qian Xu
> > if (isNull(foo) || > isNull(foo.getBar) || > isNull(foo.getBar.getBar2) > { > return false; > } Update: If minimal evaluation is not always enabled, and foo.getBar is NULL. I will get a segfault when evaluating foo.getBar.getBar2.

minimal evaluation

2009-04-06 Thread Qian Xu
Hi All, Is minimal evaluation always enabled in D? I want to write a function IsNull(), so that I can check the precondition as follows: if (isNull(foo) || isNull(foo.getBar) || isNull(foo.getBar.getBar2) { return false; } // normal code goes here If an argument is null,

Re: Wht std.complex is needed?

2009-04-06 Thread Don
bearophile wrote: Sam Hu: Doesn't D already has the built-in types cfloat, cdouble, creal, ifloat, idouble, and ireal?What's the advantage having complex class instead? The intention is that cfloat, cdouble,... will be deprecated eventually. I don't think std.complex should be part of Phobo

Re: Wht std.complex is needed?

2009-04-06 Thread bearophile
Sam Hu Wrote: >What's the disadvantage to have the built-in type of i-type?< I think the answer is: It's another type added to the language, with its specific semantics, so it adds a bit of complexity to the language. And most people today don't seem to use complex types in D1 much, so they thin

Re: Wht std.complex is needed?

2009-04-06 Thread Sam Hu
Thank you! Anothe silly question then:What's the disadvantage to have the built-in type of i-type? Regards, Sam

Re: Wht std.complex is needed?

2009-04-06 Thread bearophile
Sam Hu: > Doesn't D already has the built-in types cfloat, cdouble, creal, ifloat, > idouble, and ireal?What's the advantage having complex class instead? Some people have discussed/complained that complex types aren't worth being built-ins, so the *struct* Complex of std.complex of D2 will rep

Wht std.complex is needed?

2009-04-06 Thread Sam Hu
Hello everyone! Doesn't D already has the built-in types cfloat, cdouble, creal, ifloat, idouble, and ireal?What's the advantage having complex class instead? Thanks and best regards, Sam

Re: Format.convert problme

2009-04-06 Thread grauzone
Qian Xu wrote: grauzone wrote: Check if the variable is a pointer, and if yes, dereference it: alias typeof(i) T; static if (is(T T2 : T2*)) { T2 i2 = *i; Format.convert("{}", i2); } else { Format.convert("{}", i); } Hi again, I cannot compile this code What exactly are you doing? What d

Re: Format.convert problme

2009-04-06 Thread Qian Xu
grauzone wrote: > > Check if the variable is a pointer, and if yes, dereference it: > > alias typeof(i) T; > static if (is(T T2 : T2*)) { > T2 i2 = *i; > Format.convert("{}", i2); > } else { > Format.convert("{}", i); > } Hi again, I cannot compile this code