I'm currently working on implementing demangling of ELF C++ symbols according to

https://en.wikipedia.org/wiki/Name_mangling

A reoccurring pattern high-level pattern is to use the std.algorithm: findSplit.* functions to make algorithm single-pass when possible.

I'm however lacking a variant of this that takes a condition template argument instead of an input range element as function parameter.

Something like

auto findSplitBefore(alias condition, R)(R range) if (isInputRange!R)
{
    import std.algorithm: until;
    auto hit = range.until!condition;
    auto rest = "";
    return tuple(hit, rest);
}

unittest
{
    import std.algorithm: equal;
    import std.ascii: isDigit;
    auto x = "11ab".findSplitBefore!(a => !a.isDigit);
    assert(equal(x[0], "11"));
    /* assert(equal(x[1], "ab")); */
}

But how do I get the second part in a single pass?

Is copying (duplicating) the existing Phobos implementations the only alternative here?

If so I believe we should generalize these Phobos algorithms into the variants described above and implement the old ones by calling the generalized ones typically as

auto findSplit(R)(R range, E element) if (isInputRange!R)
{
    return range.findSplit!(a => a == element);
}

BTW: Does anybody have any good refs on ELF C++ demangling. The wikipedia article is a bit sparse.

Destroy!

Reply via email to