IFTI with value / template value parameter shadowing

Mathias LANG pro.mathias.lang at gmail.com
Sat Feb 22 18:46:21 PST 2014


Hi everyone,
I recently end up with the following code:

----
import std.stdio;

T IFTI_Type(T)(T value)       { return value; }

int IFTI_Value(int n)(int n)  { return n; }

int Shadowing_FTW(int n)()
{
    writeln(n);
    int n = 42;                     // Will print 6
    return n;
}


void    main()
{
     writeln(IFTI_Type(5));        // Will print 5
     writeln(Shadowing_FTW!6());   // Will print 42
     // This doesn't compile
     //writeln(IFTI_Value(5));
     writeln(IFTI_Value!5(8));     // Will print 8
}
----

This will print:
5
6
42
8

So from the commented call to IFTI_Value, I guessed that IFTI is 
not working for values. Is that intended behavior, or a bug ?
In addition it looks like template parameter are not considered 
while looking if a symbol with shadow another one. I didn't find 
anything on the bugtracker but 
(this)[https://d.puremagic.com/issues/show_bug.cgi?id=6980], but 
it's only related.


More information about the Digitalmars-d-learn mailing list