January 15, 2009 Re: easy way to output a struct? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | bearophile schrieb:
> Hoenir:
>> So it needs to be recursive somehow.
>
> The stuff I have linked you is recursive, of course.
>
Thanks. That's a whole lot of stuff.
Guess I really need to dig deeper into template stuff.
|
January 15, 2009 Re: easy way to output a struct? | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | BCS schrieb:
> I have a partial solution here: http://www.dsource.org/projects/scrapple/browser/trunk/log_api/LogAPI.d
>
> Feel free to steal whatever you want from it. If you are really adventures and want to, I can get you SVN access and you can dump stuff back into that.
>
Why is that "is" used here:
static if(is(a == char*))
I know is is normally used for identity comparison, but what does it do here?
Also, I've never seen something like that (I mean that ":"):
else static if(is(a : int))
|
January 16, 2009 Re: easy way to output a struct? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hoenir | On Thu, Jan 15, 2009 at 6:57 PM, Hoenir <mrmocool@gmx.de> wrote: > Why is that "is" used here: > static if(is(a == char*)) > > I know is is normally used for identity comparison, but what does it do here? is(blah blah) is a completely different thing than "x is y" ;) is() is used to test, at compile time, for some type-related information. It also has some stranger forms that allows it to introduce symbols that are bound to smaller pieces of types (for example, it can be used to get the return type or parameter types of a function or delegate). is(a == char*) returns true if the type 'a' is char*, and false otherwise. > Also, I've never seen something like that (I mean that ":"): > else static if(is(a : int)) The : is similar to ==, but means "implicitly." While is(a == int) returns true only if the type 'a' is int, is(a : int) returns true if the type 'a' is _implicitly_ convertible to int, including things like short and dchar. |
January 16, 2009 Re: easy way to output a struct? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Thanks for your explanation. Is there any good resource about that stuff other than http://www.digitalmars.com/d/1.0/template.html |
January 16, 2009 Re: easy way to output a struct? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hoenir | On Fri, Jan 16, 2009 at 2:46 AM, Hoenir <mrmocool@gmx.de> wrote: > Thanks for your explanation. > Is there any good resource about that stuff other than > http://www.digitalmars.com/d/1.0/template.html > Yeah. http://www.digitalmars.com/d/1.0/expression.html#IsExpression |
January 16, 2009 Re: easy way to output a struct? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hoenir | Reply to Hoenir,
> BCS schrieb:
>
>> I have a partial solution here:
>> http://www.dsource.org/projects/scrapple/browser/trunk/log_api/LogAPI
>> .d
>>
>> Feel free to steal whatever you want from it. If you are really
>> adventures and want to, I can get you SVN access and you can dump
>> stuff back into that.
>>
> Why is that "is" used here:
> static if(is(a == char*))
> I know is is normally used for identity comparison, but what does it
> do here?
>
> Also, I've never seen something like that (I mean that ":"): else
> static if(is(a : int))
>
the code with some annotations. It should be pointed out that the code is only designed to deal with C types)
// If the variable is a C-string, print it as such
static if(is(a == char*)) writef(`, "%s"`, t[i][0..strlen(t[i])]);
// if the variable is implicitly castable to int print it as such
else static if(is(a : int)) writef(", %d", t[i]);
// otherwise print the type name and the value (hope write can deal with it)
else writef(", [%s]%s", a.stringof,t[i]);
|
Copyright © 1999-2021 by the D Language Foundation