digitalmars.D.learn - Forwarding Uncopyable Static Array Elements
- =?UTF-8?B?Tm9yZGzDtnc=?= (15/15) Sep 17 2017 How can
- =?UTF-8?B?Tm9yZGzDtnc=?= (2/5) Sep 17 2017 That is, when `T` is uncopyable.
- =?UTF-8?B?Tm9yZGzDtnc=?= (24/39) Sep 17 2017 This works for me
How can
T[n] asStatic(T, size_t n)(T[n] arr)
{
import std.traits : isCopyable;
static if (isCopyable!T)
{
return arr;
}
else
{
static assert(false, "TODO support forwarding of
uncopyable elements");
}
}
be extended to support uncopyable element types?
Sep 17 2017
On Sunday, 17 September 2017 at 13:00:04 UTC, Nordlöw wrote:How can ... be extended to support uncopyable element types?That is, when `T` is uncopyable.
Sep 17 2017
On Sunday, 17 September 2017 at 13:00:04 UTC, Nordlöw wrote:
How can
T[n] asStatic(T, size_t n)(T[n] arr)
{
import std.traits : isCopyable;
static if (isCopyable!T)
{
return arr;
}
else
{
static assert(false, "TODO support forwarding of
uncopyable elements");
}
}
be extended to support uncopyable element types?
This works for me
T[n] asStatic(T, size_t n)(T[n] x)
{
import std.traits : isCopyable;
static if (isCopyable!T)
{
return x;
}
else
{
T[n] y = void;
// TODO why doesn't this work here?
// import std.algorithm.mutation : moveEmplaceAll;
// moveEmplaceAll(x[], y[]);
foreach (const ix, ref value; x)
{
import std.algorithm.mutation : move;
move(value, y[ix]);
}
return y;
}
}
Why does `moveEmplaceAll` error here?
Sep 17 2017









=?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> 