Consider this code:
struct Node
{
int payload;
Node* next;
uint refs;
}
void main()
{
import core.stdc.stdlib : malloc;
void[] buf = malloc(Node.sizeof)[0 .. Node.sizeof];
import std.conv : emplace;
const Node* n = emplace!(Node)(buf, 42, null, 10);
}
Essentially the attempt is to create a new const Node object in the specified buffer. The code should work, but fails to compile with an obscure error message.
Comment #1 by petar.p.kirov — 2015-11-10T21:16:55Z
Andrei, I think you meant to write:
const Node* n = emplace!(const Node)(buf, 42, null, 10);
Comment #2 by andrei — 2015-11-10T22:21:46Z
(In reply to ZombineDev from comment #1)
> Andrei, I think you meant to write:
> const Node* n = emplace!(const Node)(buf, 42, null, 10);
Correct, thanks! By mistake I pasted the minimally changed code that does work.