Move and CTFE

Q. Schroll at
Wed May 30 20:42:38 UTC 2018

It seems one cannot std.algorithm.mutation.move objects 
explicitly. Say I have a non-copyable type

     struct NoCopy
         int payload; // some payload
     pure nothrow @nogc @safe @disable:
         this(this); // make it non copyable

that is being used in a compile-time function evaluation where 
values are being moved.

     int f() pure nothrow @nogc @safe
         import std.algorithm.mutation : move;
         NoCopy nc = NoCopy(1), nc2 = NoCopy(3);
         nc = move(nc2);
         return 0;

     static assert(f() == 0); // trigger CTFE

It fails because move() cannot be executed at compile time. The 
     "memcpy cannot be interpreted at compile time, because it has 
no available source code"
sounds very suspicious. Shouldn't it be possible to move at CTFE, 
too, or does it mean, non-copyable types are practically unusable 
for CTFE?

More information about the Digitalmars-d-learn mailing list