June 08, 2005 Re: DMD 0.126 - static if broken/fishy? examples attached | ||||
---|---|---|---|---|
| ||||
Posted in reply to clayasaurus | Both of them compile cleanly when I try it. |
June 08, 2005 Re: DMD 0.126 - static if broken/fishy? examples attached | ||||
---|---|---|---|---|
| ||||
Posted in reply to clayasaurus | Ok.. the 'fix' that I used is still broken. Here's what I have to do for it to compile...
static if (is(T : real))
{
prim!(T)(dat);
}
static if (is(T : Object))
{
obj!(T)(dat);
}
static if (!is(T : Object) && !is(T : real))
{
str!(T)(dat);
}
weird, no?
clayasaurus wrote:
> Walter wrote:
>
>> Added inner classes.
>>
>> http://www.digitalmars.com/d/changelog.html
>>
>>
>>
>
> Ok. I've had some problems switching from iftype to static if (is(T:real)), but now I've come across something that really doesn't make any sense...
>
> I've attached two files, and the question i ask is, why does test1.d fail to compile, while test2.d compiles, if the only difference between them is...
>
> from test1.d...
>
> static if(is(T : real))
> {
> inta!(T)(dat);
> }
> else if(is(T : Object))
> {
> obj!(T)(dat);
> }
> else // assume it is a struct
> {
> str!(T)(dat);
> }
>
> vs this from test2.d...
>
> static if(is(T : Object))
> {
> obj!(T)(dat);
> }
> else // assume it is a struct
> {
> str!(T)(dat);
> }
>
> test1.d blurts out the compiler error, ...
>
> test1.d(35): incompatible types for ((dat) === (null)): 'Point' and 'void*'
> test1.d(36): cannot implicitly convert expression (new Point *) of type Point * to Point
> test1.d(14): template instance temp.Foo.obj!(Point ) error instantiating
> test1.d(18): function expected before (), not template instance str!(Point ) of type void
> test1.d(70): template instance temp.Foo.bar!(Point ) error instantiating
>
> Are you not allowed to use static if for multiple layers? I figured out I can fix it by using ...
>
> static if(is(T : real))
> {
> inta!(T)(dat);
> }
> static if(is(T : Object))
> {
> obj!(T)(dat);
> }
> else // assume it is a struct
> {
> str!(T)(dat);
> }
>
> -clayasaurus
>
>
> ------------------------------------------------------------------------
>
> module temp; class Foo
> {
> template bar(T)
> {
> void bar(inout T dat)
> {
> static if(is(T : real))
> {
> inta!(T)(dat); }
> static if(is(T : Object))
> {
> obj!(T)(dat); }
> else // assume it is a struct
> {
> str!(T)(dat);
> }
> }
> }
>
> template inta(T)
> {
> void inta(inout T dat)
> {
> dat = 3; }
> }
>
> template obj(T)
> {
> void obj(inout T dat)
> {
> if (dat is null) // here lies the problem?
> dat = new T; }
> }
>
> template str(T)
> {
> void str(inout T dat)
> {
> }
> }
> }
>
>
> struct Point
> {
> float x, y;
>
> void desc(Foo s)
> {
> s.bar!(float)(x);
> s.bar!(float)(y); }
> }
>
> int main()
> {
> Point p;
> p.x = 3.14159; p.y = 1.41421;
>
> Foo foo = new Foo;
>
>
>
> foo.bar!(Point)(p);
>
> return 0;
> }
>
>
> ------------------------------------------------------------------------
>
> module temp; class Foo
> {
> template bar(T)
> {
> void bar(inout T dat)
> {
> static if(is(T : Object))
> {
> obj!(T)(dat); }
> else // assume it is a struct
> {
> str!(T)(dat);
> }
> }
> }
>
> template inta(T)
> {
> void inta(inout T dat)
> {
> dat = 3; }
> }
>
> template obj(T)
> {
> void obj(inout T dat)
> {
> if (dat is null) // here lies the problem?
> dat = new T; }
> }
>
> template str(T)
> {
> void str(inout T dat)
> {
> }
> }
> }
>
>
> struct Point
> {
> float x, y;
>
> void desc(Foo s)
> {
> s.bar!(float)(x);
> s.bar!(float)(y); }
> }
>
> int main()
> {
> Point p;
> p.x = 3.14159; p.y = 1.41421;
>
> Foo foo = new Foo;
>
> foo.bar!(Point)(p);
>
> return 0;
> }
|
June 08, 2005 Re: DMD 0.126 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Walter wrote:
> But that's the point of having the -d switch!
>
> And since compiler updates are free, there's no reason to support older
> versions once GDC gets updated.
I've been wondering whether it would be worthwhile to
add something to flag which language version is needed ?
Like it's done in Perl:
"require v5.6.1;"
(sure there are others)
Maybe a pragma or something would do the trick in D code ?
The idea is to forward : "this code needs DMD >= 0.126".
--anders
|
June 08, 2005 Re: DMD 0.126 - static if broken/fishy? examples attached | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Attachments: | Walter wrote:
> Both of them compile cleanly when I try it.
>
>
lol. ahh. i must have put the wrong files up. *smacks head*
here is the test1 that shouldn't compile...
|
June 08, 2005 Re: DMD 0.126 - static if broken/fishy? examples attached | ||||
---|---|---|---|---|
| ||||
Posted in reply to clayasaurus Attachments: | Here is the original that doesn't compile, and better shows what exactly I was trying to do.
clayasaurus wrote:
> Walter wrote:
>
>> Both of them compile cleanly when I try it.
>>
>>
>
> lol. ahh. i must have put the wrong files up. *smacks head*
>
> here is the test1 that shouldn't compile...
>
>
> ------------------------------------------------------------------------
>
> module temp;
> class Foo
> {
> template bar(T)
> {
> void bar(inout T dat)
> {
> static if(is(T : real))
> {
> inta!(T)(dat);
> }
> if(is(T : Object))
> {
> obj!(T)(dat);
> }
> else // assume it is a struct
> {
> str!(T)(dat);
> }
> }
> }
>
> template inta(T)
> {
> void inta(inout T dat)
> {
> dat = 3;
> }
> }
>
> template obj(T)
> {
> void obj(inout T dat)
> {
> if (dat is null) // here lies the problem?
> dat = new T;
>
> }
> }
>
> template str(T)
> {
> void str(inout T dat)
> {
> }
> }
> }
>
>
> struct Point
> {
> float x, y;
>
> void desc(Foo s)
> {
> s.bar!(float)(x);
> s.bar!(float)(y);
> }
> }
>
> int main()
> {
> Point p;
> p.x = 3.14159; p.y = 1.41421;
>
> Foo foo = new Foo;
>
> foo.bar!(Point)(p);
>
> return 0;
> }
|
June 08, 2005 Re: DMD 0.126 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Walter wrote:
> "Stewart Gordon" <smjg_1998@yahoo.com> wrote in message
> news:d86gob$1g0e$1@digitaldaemon.com...
>
>>zwang wrote:
>>
>>>Walter wrote:
>>>
>>>
>>>>Added inner classes.
>>>>
>>>>http://www.digitalmars.com/d/changelog.html
>>>
>>>Wow, that looks like a major update. Thanks!
>>>I'm not sure whether it's time to upgrade, though.
>>>So many things are deprecated in version 0.126.
>>
>>And so many things changed their behaviour. Like nested classes and
>>unsuccessful AA lookups.
>
>
> With the deprecation detection by the compiler, finding the problem areas is
> pretty simple, and they're easilly fixed.
>
>
True. Fixing the problems are fairly easy. What I'm concerned is the compatibility issue.
|
June 08, 2005 Re: DMD 0.126 - static if broken/fishy? examples attached | ||||
---|---|---|---|---|
| ||||
Posted in reply to clayasaurus | Replace: "else if" with: "else static if" |
June 08, 2005 Re: DMD 0.126 - static if broken/fishy? examples attached | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Walter wrote:
> Replace:
> "else if"
> with:
> "else static if"
>
>
thanks :-)
|
June 08, 2005 Re: DMD 0.126 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Walter schrieb am Tue, 7 Jun 2005 22:17:50 -0700: > Added inner classes. > > http://www.digitalmars.com/d/changelog.html > "!=0 means gag reporting of errors" now that's one of the best sourcecode documentations ever ;) -----BEGIN PGP SIGNATURE----- iD8DBQFCpzOR3w+/yD4P9tIRApeeAJ965VNqlrGF3XgIjLgoMYovQtJ01QCbBJNF D9kl4tCyZaCCEvE0nF37LXU= =8rlp -----END PGP SIGNATURE----- |
June 08, 2005 Re: DMD 0.126 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | The following: void sum(int[] ar ...) In the documentation for the new typesafe variadic parameters... here: http://www.digitalmars.com/d/function.html#variadic Should probably read: int sum(int[] ar ...) No? -[Unknown] > Added inner classes. > > http://www.digitalmars.com/d/changelog.html |
Copyright © 1999-2021 by the D Language Foundation