compile-time function return element of Tuple -------------------------------------------------------------------- import std.stdio; template Tuple(A...) { alias A Tuple; } template eval(A...) { alias A eval; } alias Tuple!("a","b") foo; char[] retsth(int i) { return foo[i]; } //Error: Integer constant expression expected instead of cast(uint)i void main() { writefln(eval!(foo[0])); //this is working writefln(eval!(retsth(0))); } -------------------------------------------------------------------- compile-time function return element of const array -------------------------------------------------------------------- import std.stdio; template eval(A...) { alias A eval; } const char[] foo[2] = ["a","b"]; char[] retsth(int i) { return foo[i]; } void main() { writefln(eval!(foo[0])); //this is working (see #975) writefln(eval!(retsth(0))); //but this makes dmd crash } --------------------------------------------------------------------
Is this related to the bug ? -------------------------------------------------------------------- import std.stdio; template eval(A...) { alias A eval; } char[] retsth(int i) { const char[] foo[2] = ["a","b"]; return foo[i]; } //Error: cannot evaluate retsth(0) at compile time //Error: expression eval!(retsth(0)) is void and has no value void main() { writefln(eval!(retsth(0))); } -------------------------------------------------------------------- PS: Ultimately I would like to be able to do: writefln(eval!(std.string.stripl(" test")); Maybe some more string operations could be compile-time ready ? I am not sure whether this will work if this bug get's fixed, so maybe this is a feature req ;)
Added to DStress as http://dstress.kuehne.cn/run/t/tuple_16_A.d http://dstress.kuehne.cn/run/t/tuple_16_B.d http://dstress.kuehne.cn/run/t/tuple_16_C.d http://dstress.kuehne.cn/run/t/tuple_16_D.d
The first example is not a bug; tuples must be evaluatable at compile time, and i of retsth(i) is not known at compile time when object code is generated for it. The other two are bugs.
Fixed DMD 1.009
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル