Thread overview | ||||||
---|---|---|---|---|---|---|
|
July 19, 2013 stringof alias | ||||
---|---|---|---|---|
| ||||
I have a template template T(alias t) { pragma(msg, t.stringof); .... other stuff ... } which I use in a class and pass fields/members to. D complains that t does not have a this. I'd just like to print the literal text that was passed to T. (which I actually do in ctfe) This is so I can have some sort of debug output of what was passed to t. |
July 19, 2013 Re: stringof alias | ||||
---|---|---|---|---|
| ||||
Posted in reply to JS | On Friday, 19 July 2013 at 08:02:45 UTC, JS wrote:
> I have a template
>
> template T(alias t)
> {
> pragma(msg, t.stringof);
> .... other stuff ...
> }
>
> which I use in a class and pass fields/members to.
>
> D complains that t does not have a this.
>
> I'd just like to print the literal text that was passed to T. (which I actually do in ctfe) This is so I can have some sort of debug output of what was passed to t.
that error is probably related to what you're passing as t, which leads to the obvious question: what sort of things are you passing as t?
|
July 19, 2013 Re: stringof alias | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | On Friday, 19 July 2013 at 08:08:27 UTC, John Colvin wrote:
> On Friday, 19 July 2013 at 08:02:45 UTC, JS wrote:
>> I have a template
>>
>> template T(alias t)
>> {
>> pragma(msg, t.stringof);
>> .... other stuff ...
>> }
>>
>> which I use in a class and pass fields/members to.
>>
>> D complains that t does not have a this.
>>
>> I'd just like to print the literal text that was passed to T. (which I actually do in ctfe) This is so I can have some sort of debug output of what was passed to t.
>
> that error is probably related to what you're passing as t, which leads to the obvious question: what sort of things are you passing as t?
Yeah, I forgot to add a private local variable and it was complaining... I didn't realize this because it was working before I started refactoring stuff.
I guess it would be nice to assert a proper error if t doesn't exist rather than the error it gave. (I'm suppose to be passing it a field of a class so it should exist)
Is there any way to test for "existance" of an alias?
|
July 19, 2013 Re: stringof alias | ||||
---|---|---|---|---|
| ||||
Posted in reply to JS | On 07/19/2013 02:02 AM, JS wrote: > On Friday, 19 July 2013 at 08:08:27 UTC, John Colvin wrote: >> On Friday, 19 July 2013 at 08:02:45 UTC, JS wrote: >>> I have a template >>> >>> template T(alias t) >>> { >>> pragma(msg, t.stringof); >>> .... other stuff ... >>> } >>> >>> which I use in a class and pass fields/members to. I read everything you wrote and came up with this: template T(alias t) { pragma(msg, t.stringof); } class C { int i; void foo() { mixin T!i; mixin T!j; } } void main() { auto c = new C(); } >>> D complains that t does not have a this. Hm... It does not do that for me. > I guess it would be nice to assert a proper error if t doesn't exist > rather than the error it gave. That is exactly what dmd does: Error: undefined identifier j, did you mean variable i? > (I'm suppose to be passing it a field of > a class so it should exist) > > Is there any way to test for "existance" of an alias? Probably. But I suspect your code is something different from what I understood. Ali |
Copyright © 1999-2021 by the D Language Foundation