chunkBy array at compile time

Steven Schveighoffer schveiguy at gmail.com
Wed Dec 19 15:38:06 UTC 2018


On 12/19/18 3:20 AM, Andrey wrote:
> Hi,
> I have got this code:
>> import std.array : array;
>> import std.algorithm.mutation;
>> import std.algorithm.iteration;
>> import std.stdio;
>>
>> void main()
>> {
>>     string input = "sieviaghp";
>>     enum data = ["emo", "emoze", "emow", "emuo", "evuo", "ete", "ie", 
>> "vuo", "sie", "w"];
>>
>>     enum index = 3;
>>     enum filtered = data.filter!(value => value.length > index).array();
>>     pragma(msg, filtered);
>>
>>     enum GetSeq = filtered.chunkBy!((first, second) => first[index] == 
>> second[index]);//.array();
>>     pragma(msg, GetSeq);
>> }
> There is an array of strings. I filter it using length of each element. 
> Result should be:
>> ["emoze", "emow", "emuo", "evuo"]
> Then I want to chuck it using symbol at position 'index' to get this:
>> ["emoze"] // group 1, symbol 'z'
>> ["emow"] // group 2, symbol 'w'
>> ["emuo", "evuo"] // group 1, symbol 'o'
> Everything I'm doing at COMPILE time!
> 
> But when I try to build program I get this strange error:
>> /dlang/dmd/linux/bin64/../../src/druntime/import/core/memory.d(827): 
>> Error: `fakePureErrno` cannot be interpreted at compile time, because 
>> it has no available source code
>> onlineapp.d(15):        compile time context created here
> 

Probably because it's using RefCounted.

Looking at the code for chunkBy, it seems to me that the implementation 
is quite complex for what in my head should be a simple wrapper...

-Steve


More information about the Digitalmars-d-learn mailing list