[phobos] What does this code do?
David Simcha
dsimcha at gmail.com
Mon Aug 16 17:01:11 PDT 2010
I'm trying to revamp array() to follow Bearophile's very good suggestion
of letting any foreachable object be convertible to an array even if
it's opApply-based, not a range. My efforts have been blocked by this
cryptic piece of code:
foreach (ref e; result)
{
// hacky
static if (is(typeof(&e.opAssign)))
{
// this should be in-place construction
new(&e) E(r.front);
}
else
{
e = r.front;
}
r.popFront;
}
It took me awhile to even wrap my head around what the point of that
code is. First of all, why are we bypassing opAssign? Secondly, what
if the E doesn't have a constructor that takes only another E as an
argument?
More information about the phobos
mailing list