Bug 995 – compile-time function return element of Tuple / const array
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2007-02-22T06:40:00Z
Last change time
2014-02-16T15:26:06Z
Assigned to
bugzilla
Creator
Daniel919
Comments
Comment #0 by Daniel919 — 2007-02-22T06:40:12Z
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
}
--------------------------------------------------------------------
Comment #1 by Daniel919 — 2007-02-22T11:39:51Z
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 ;)
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.