splitter trouble
    Ali Çehreli via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Sun Oct 30 16:57:11 PDT 2016
    
    
  
While working on a solution for Alfred Newman's thread, I came up with 
the following interim solution, which compiled but failed:
auto parse(R, S)(R range, S separators) {
     import std.algorithm : splitter, filter, canFind;
     import std.range : empty;
     static bool pred(E, S)(E e, S s) {
         return s.canFind(e);
     }
     return range.splitter!pred(separators).filter!(token => !token.empty);
}
unittest {
     import std.algorithm : equal;
     import std.string : format;
     auto parsed = parse("_My   input.string", " _,.");
     assert(parsed.equal([ "My", "input", "string" ]), format("%s", 
parsed));
}
void main() {
}
The unit test fails and prints
["put", "ing"]
not the expected
["My", "input", "string"].
How is that happening? Am I unintentionally hitting a weird overload of 
splitter?
Ali
    
    
More information about the Digitalmars-d-learn
mailing list