December 08, 2017
Hi, I'm having a bit a trouble doing some compile time parsing. This works:

immutable str = "he-.llo-the.re";
immutable separators = "-.";
enum a = str.splitter(separators).array;

But this does not:

enum b = str.splitter!(a => separators.canFind(a)).array;

The error is: cannot deduce function from argument types !((a) => separators.canFind(a))(immutable(string))

And this does:

enum c = str.splitter!(a => a == a).array;

And this does not:

enum d = str.splitter!(a => a == separators).array;

What am I missing?

Thanks!


December 07, 2017
On 12/07/2017 04:45 PM, aliak wrote:
> Hi, I'm having a bit a trouble doing some compile time parsing. This works:
> 
> immutable str = "he-.llo-the.re";
> immutable separators = "-.";
> enum a = str.splitter(separators).array;
> 
> But this does not:
> 
> enum b = str.splitter!(a => separators.canFind(a)).array;
> 
> The error is: cannot deduce function from argument types !((a) => separators.canFind(a))(immutable(string))
> 
> And this does:
> 
> enum c = str.splitter!(a => a == a).array;
> 
> And this does not:
> 
> enum d = str.splitter!(a => a == separators).array;
> 
> What am I missing?
> 
> Thanks!
> 
> 

Most work with 2.076 for me. 'd' does not work because while str.front is dchar, separators is a string, so 'a == separators' does not compile:

import std.stdio;
import std.algorithm;
import std.range;

void main() {
    immutable str = "he-.llo-the.re";
    immutable separators = "-.";

    enum a = str.splitter(separators).array;
    enum b = str.splitter!(a => separators.canFind(a)).array;
    enum c = str.splitter!(a => a == a).array;
    // enum d = str.splitter!(a => a == separators).array;

    writeln(a);
    writeln(b);
    writeln(c);
}

["he", "llo-the.re"]
["he", "", "llo", "the", "re"]
["", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]

Ali