is my code to get CTFE instantiated object valid D ?
ag0aep6g via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat May 28 09:27:47 PDT 2016
On 05/28/2016 06:09 PM, chmike wrote:
> In the following instruction of the above commit, what effect has the []
> after init ?
>
> _store[0 .. __traits(classInstanceSize, T)] = typeid(T).init[];
>
> T is a template argument that is a class derived from Error.
>
> I couldn't find an explanation here
> https://dlang.org/spec/property.html#init.
>
> I saw that this is a concise implementation of what is being done in
> emplace().
`typeid(T).init` is a different `init` than the one you linked. We have
since renamed it to `initializer` to fix the name clash.
Documentation is here:
http://dlang.org/phobos/object.html#.TypeInfo.initializer
As you can see there, it's a `const(void)[]`.
The statement is a form of "array copying":
http://dlang.org/spec/arrays.html#array-copying
As you can see there, it would also work without the `[]`. With them
it's a bit clearer that array copying is going on, and not "array
setting" (next section on the spec page).
More information about the Digitalmars-d-learn
mailing list