template alias = parameter
Dicebot
public at dicebot.lv
Tue Sep 17 04:31:34 PDT 2013
On Tuesday, 17 September 2013 at 11:24:10 UTC, Luís Marques wrote:
> Could you please comment on the following behaviors? Are all of
> them intended? Are they internally coherent, with respect to
> each
> other?
Looks fine to me.
> 1)
> void foo(alias f)(int f)
> {
> writeln(f);
> }
>
> foo(42);
>
> Error: does not match template
`alias` is never inferred so error is expected. You did not
provide any template parameters to foo. `void foo(T)(T f)` would
have worked because `T` can be inferred.
> 2)
> ...
> foo!(42)(42);
>
> > 42
Explicit template parameter + normal parameter. Name of normal
parameter shadows alias name (would have expected a warning/error
here tbh).
> 3)
> ...
> foo!(7)(42);
>
> > 42
Same as (2).
> 4)
> void foo(alias f)(int g=f)
> {
> writeln(g);
> }
>
> foo(42);
>
> Error: does not match template
Again, you do not provide template parameter, it can't match.
`foo!(42)()` should have worked here.
> 5)
> void foo(alias f=42)(int g=f)
> {
> writeln(g);
> }
>
> foo();
>
> > 42
Default parameters can be used everywhere so no need to provide
any parameter explicitly.
More information about the Digitalmars-d
mailing list