From 54da39a2df6fd230d2c888e1d54adb29780983ee Mon Sep 17 00:00:00 2001 From: Dmitry Olshansky Date: Thu, 16 Mar 2017 16:57:34 +0100 Subject: [PATCH] Make std.algo.copy CTFE-able --- std/algorithm/mutation.d | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/std/algorithm/mutation.d b/std/algorithm/mutation.d index 5cb4f125ed9..f1aa9ee4769 100644 --- a/std/algorithm/mutation.d +++ b/std/algorithm/mutation.d @@ -375,7 +375,7 @@ if (areCopyCompatibleArrays!(SourceRange, TargetRange)) assert(tlen >= slen, "Cannot copy a source range into a smaller target range."); - immutable overlaps = () @trusted { + immutable overlaps = __ctfe || () @trusted { return source.ptr < target.ptr + tlen && target.ptr < source.ptr + slen; }(); @@ -486,6 +486,14 @@ $(HTTP sgi.com/tech/stl/copy_backward.html, STL's copy_backward'): assert(dest == [0, 0, 1, 2, 4]); } +// Test CTFE copy. +@safe unittest +{ + enum c = copy([1,2,3], [4,5,6,7]); + assert(c == [7]); +} + + @safe unittest { import std.algorithm.iteration : filter;