Fastest Way to Append Multiple Elements to an Array

"Nordlöw" via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Dec 30 14:56:13 PST 2014


On Saturday, 27 December 2014 at 07:34:43 UTC, Tobias Pankrath 
wrote:
> On Friday, 26 December 2014 at 16:31:48 UTC, Nordlöw wrote:
>> On Friday, 26 December 2014 at 16:29:56 UTC, Nordlöw wrote:
>>> See my update at
>>>
>>> https://github.com/nordlow/justd/blob/master/algorithm_ex.d#L1602
>>>
>>> which tries to merge all the ideas into one adapting 
>>> algorithm :)
>>>
>>> Destroy!
>>
>> BTW:
>
> writeln(estimateLength([1,2,3],[1,2,3]));
>
> If appending to an int[] this must print 6, if appending to an
> int[][] it should
> print 2.

Do you have a suitable proposal for a CT-expression that checks 
if an argument of type E to estimateLength() will be treated as 
T[] in the append?

My current suggestion is

     isArray!A && is(T == ElementType!(A)) && hasLength!A

in use at

https://github.com/nordlow/justd/blob/master/algorithm_ex.d#L1602

with the hope of being compatible with static arrays.

However uncommenting

https://github.com/nordlow/justd/blob/master/algorithm_ex.d#L1680

gives compilation error as

algorithm_ex.d(1658,20): Error: template 
std.array.Appender!(int[]).Appender.put cannot deduce function 
from argument types !()(int[3]), candidates are:
/home/per/opt/x86_64-unknown-linux-gnu/dmd/linux/bin64/src/phobos/std/array.d(2518,10): 
        std.array.Appender!(int[]).Appender.put(U)(U item) if 
(canPutItem!U)
/home/per/opt/x86_64-unknown-linux-gnu/dmd/linux/bin64/src/phobos/std/array.d(2554,10): 
        std.array.Appender!(int[]).Appender.put(Range)(Range 
items) if (canPutConstRange!Range)
/home/per/opt/x86_64-unknown-linux-gnu/dmd/linux/bin64/src/phobos/std/array.d(2563,10): 
        std.array.Appender!(int[]).Appender.put(Range)(Range 
items) if (canPutRange!Range)
algorithm_ex.d(1658,20): Error: template 
std.array.Appender!(int[]).Appender.put cannot deduce function 
from argument types !()(int[3]), candidates are:
/home/per/opt/x86_64-unknown-linux-gnu/dmd/linux/bin64/src/phobos/std/array.d(2518,10): 
        std.array.Appender!(int[]).Appender.put(U)(U item) if 
(canPutItem!U)
/home/per/opt/x86_64-unknown-linux-gnu/dmd/linux/bin64/src/phobos/std/array.d(2554,10): 
        std.array.Appender!(int[]).Appender.put(Range)(Range 
items) if (canPutConstRange!Range)
/home/per/opt/x86_64-unknown-linux-gnu/dmd/linux/bin64/src/phobos/std/array.d(2563,10): 
        std.array.Appender!(int[]).Appender.put(Range)(Range 
items) if (canPutRange!Range)
algorithm_ex.d(1681,16): Error: template instance 
algorithm_ex.append!(int, int[3], int[3]) error instantiating

Comint exited abnormally with code 1 at Tue Dec 30 23:55:33

Isn't appender compatible with static arrays?


More information about the Digitalmars-d-learn mailing list