IFTI with value / template value parameter shadowing
Marc Schütz" <schuetzm at gmx.net>
Marc Schütz" <schuetzm at gmx.net>
Sun Feb 23 03:49:24 PST 2014
On Sunday, 23 February 2014 at 02:46:24 UTC, Mathias LANG wrote:
> int IFTI_Value(int n)(int n) { return n; }
> ...
> So from the commented call to IFTI_Value, I guessed that IFTI
> is not working for values. Is that intended behavior, or a bug ?
There's no IFTI here. IFTI is about inferring a template argument
(= type) from the type of a function argument. Your template
argument is a value, not a type, so there's nothing to infer.
Not sure what you want to achieve. Do you want IFTI_Value(6) to
be instantiated as IFTI_Value!6(6)? In this case, just leave the
runtime parameter out:
int IFTI_Value(int n)() { return n; }
Of course, you will have to use the ! syntax then:
assert(IFTI_Value!6() == 6);
> 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.
I believe it works exactly as intended. The short form for
template functions is just syntactic sugar for:
template IFTI_Value(int n) {
int IFTI_Value(int n) { return n; }
}
This means that the function (runtime) parameter n is declared in
the inner scope, and is thus expected to shadow the template
parameter n in the outer scope.
More information about the Digitalmars-d-learn
mailing list