enum function can't be passed into template?

Philippe Sigaud philippe.sigaud at gmail.com
Sun Jan 20 06:51:42 PST 2013


On Sun, Jan 20, 2013 at 3:21 PM, Zhenya <zheny at list.ru> wrote:
> Hi!
> Am I doing something wrong?
>
> import std.stdio;
>
> template gun(alias f)
> {
>         void gun()
>         {
>                 f();
>         }
> }
>
> void main()
> {
>         auto str = "hello";
>         enum fun = (){writeln(str);};//replace enum -> auto to compile
>         gun!fun();
> }

fun depends on str, which is a runtime value. Either make str an enum
or put them in the module scope (which will make the auto's enum's)


More information about the Digitalmars-d-learn mailing list