The case of &T.init
Marco Leise via Digitalmars-d
digitalmars-d at puremagic.com
Tue May 19 11:40:20 PDT 2015
I was wondering why T.init is treated as a manifest constant.
Don't all .init's end up in some data segment with a
resolvable address ?
In std.conv we have:
---
//emplace helper functions
private ref T emplaceInitializer(T)(ref T chunk) @trusted pure nothrow
{
static if (!hasElaborateAssign!T && isAssignable!T)
chunk = T.init;
else
{
import core.stdc.string : memcpy;
static immutable T init = T.init;
memcpy(&chunk, &init, T.sizeof);
}
return chunk;
}
---
It seems wasteful to create duplicates of .init, so it would
be nice if one could just write:
import core.stdc.string : memcpy;
memcpy(&chunk, &T.init, T.sizeof);
Likewise it would be nice to get the a class's .init[] slice
at compile-time.
--
Marco
More information about the Digitalmars-d
mailing list