On 2012-08-02 09:43, Jonathan M Davis wrote:

For instance, I have this function which I use to generate a mixin any time
that I want to get the first code unit:

string declareFirst(R)()
     if(isForwardRange!R && is(Unqual!(ElementType!R) == dchar))
{
     static if(isNarrowString!R)
         return "Unqual!(ElementEncodingType!R) first = range[0];";
     else
         return "dchar first = range.front;";
}

So, every line using it becomes

mixin(declareFirst!R());

which really isn't any worse than

char c = str[0];

except that it works with more than just strings. Yes, it's more effort to get
the lexer working with all ranges of dchar, but I don't think that it's all
that much worse, it the result is much more flexible.

That doesn't look too bad. I'm quite happy :)

--
/Jacob Carlborg

Reply via email to