It seems pure ain't so pure after all

Steven Schveighoffer schveiguy at yahoo.com
Mon Oct 1 06:49:18 PDT 2012


On Mon, 01 Oct 2012 01:40:37 -0400, Tommi <tommitissari at hotmail.com> wrote:

> import std.stdio;
>
> int pow2(int val) pure
> {
>      if (__ctfe)
>          return 6;
>      else
>          return val * val;
> }
>
> void main()
> {
>             assert(pow2(3) == 9);
>      static assert(pow2(3) == 6);
>
>      writeln("9 = 6 ... I knew it! '6' was faking it all along");
>      readln();
> }

You have a bug in your code, here let me fix that for you:

> int pow2(int val) pure
> {
>     return val * val;
> }

OK, on to the next thread...

-Steve


More information about the Digitalmars-d mailing list