[Issue 2448] template return by reference causes seg fault
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jan 25 21:32:28 PST 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2448
andrei at metalanguage.com changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |major
------- Comment #1 from andrei at metalanguage.com 2009-01-25 23:32 -------
Adding another example and bumping this to major because it stops std.algorithm
development dead in its tracks.
template ElementType(R)
{
alias typeof({ R r; return r[0]; }()) ElementType;
}
bool empty(T)(in T[] a) { return !a.length; }
void next(T)(ref T[] a) { assert(a.length); a = a[1 .. $]; }
void retreat(T)(ref T[] a) { assert(a.length); a = a[0 .. $ - 1]; }
T head(T)(T[] a) { assert(a.length); return a[0]; }
ref T toe(T)(T[] a) { assert(a.length); return a[a.length - 1]; }
struct Retro(R)
{
private:
R _input;
public:
bool empty()
{
return _input.empty;
}
void next()
{
_input.retreat;
}
ElementType!(R) head()
{
return _input.toe;
}
}
void main()
{
void test(int[] input)
{
foreach (e; Retro!(int[])(input))
{
}
}
test([ 1 ]);
}
--
More information about the Digitalmars-d-bugs
mailing list