Should it compile?

Stanislav Blinov stanislav.blinov at gmail.com
Sat Jun 6 12:54:38 UTC 2020


On Saturday, 6 June 2020 at 11:58:06 UTC, Basile B. wrote:
> On Saturday, 6 June 2020 at 08:55:20 UTC, Jack Applegame wrote:
>> Should it compile?
>> I think, it should.
>
> maybe it shouldn't but then with another message, for example
>
>     Error, cannot `void` initialize a `const` declaration.
>
> since that makes very little sense, at least as a local 
> variable. (as a member, this can be initialized in a 
> constructor)

The moveEmpalce should compile, just like this does:

import std.conv : emplace;

emplace(&a, 'a');

But, in the case of emplacing into a const, either should be 
@system (moveEmplace is always @system, but `emplace` for this 
case is not at the moment).

One could do a

emplace(&a, move(b))

but that's more moves (and I believe current emplace even would 
insert a spurious copy there).

This is what we get for delegating emplacement and moves into a 
library instead of having appropriate intrinsics.


More information about the Digitalmars-d-learn mailing list