November 25, 2005 Re: DMD 0.140 release | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright wrote:
> Template and complex number fixes. New name demangler!
>
> http://www.digitalmars.com/d/changelog.html
>
A question: When are the implicit template properties supposed to apply? There's a interesting corner case involving properties of built-in types.
With the code
template q()
{
const char [] q = "abc";
}
const int a = q!().length;
does not compile. Fair enough, it's looking for q!().length, not q!().q.length.
Although potentially the rule for evaluating a!().b could be: look for a!().b, if not found, look for a!().a.b
I don't think this recurses, even if a!().a was a template.
So, I tried
const int a = (q!()).length;
This doesn't compile either. Based on the error message, it seems that parentheses suppress the implicit property feature. Is this behaviour intentional? (Maybe it could be useful).
Anyway,
const int a = (q!() ~ "").length
works as expected, as does:
template strlen(char [] str)
{
const int strlen = str.length;
}
const int a = strlen!(q!());
|
November 25, 2005 Re: DMD 0.140 release | ||||
---|---|---|---|---|
| ||||
Posted in reply to Don Clugston | It certainly seems it should work. I'll check into it. |
November 25, 2005 Re: DMD 0.140 release | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | "Stewart Gordon" <smjg_1998@yahoo.com> wrote in message news:dm6rdm$57i$1@digitaldaemon.com... > Excellent! Only, I think you mean 28264 or 28426, not 28246. > > And you mistyped my name in the comment to fromMBSz. Sorry about that. I'll fix it. |
November 26, 2005 Re: DMD 0.140 release | ||||
---|---|---|---|---|
| ||||
Posted in reply to Don Clugston | "Don Clugston" <dac@nospam.com.au> wrote in message news:dm72ee$bvp$1@digitaldaemon.com... > With the code > > template q() > { > const char [] q = "abc"; > } > > const int a = q!().length; > > does not compile. I tried this with 0.140: template q() { const char [] q = "abc"; } const int a = q!().length; void main() { printf("a = %d\n", a); } and got: a = 3 as the output. |
November 28, 2005 Re: DMD 0.140 release | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Sorry, I got that a bit wrong. Here's a minimal test case:
--------------
template cat(int n)
{
const int dog = n;
}
const char [] q = "qqqq";
const int thisfails = cat!(q.length).dog;
--------------
bug.d(9): no property 'length' for type 'char[]'
----------------
But if you replace the last line with:
const int a = q.length;
const int thisworks = cat!(a).dog;
it works. So it seems to be a simple order-of-evaluation bug that doesn't have anything to do with implicit template properties. I'll post it to d.D.bugs.
Walter Bright wrote:
> "Don Clugston" <dac@nospam.com.au> wrote in message
> news:dm72ee$bvp$1@digitaldaemon.com...
>
>>With the code
>>
>>template q()
>>{
>> const char [] q = "abc";
>>}
>>
>>const int a = q!().length;
>>
>>does not compile.
>
>
> I tried this with 0.140:
>
> template q()
> {
> const char [] q = "abc";
> }
>
> const int a = q!().length;
>
> void main()
> {
> printf("a = %d\n", a);
> }
>
> and got:
> a = 3
> as the output.
>
>
|
Copyright © 1999-2021 by the D Language Foundation