[Issue 9786] Allow [non-member|UFCS] implementation of operators

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Mar 22 14:55:12 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9786



--- Comment #1 from monarchdodra at gmail.com 2013-03-22 14:55:11 PDT ---
Extracted from 7177, this is an example of how and why we'd want this:

//--------
import std.stdio;
import std.range;

//opDollar for any range with length
auto opDollar(R)(auto ref R r)
    if (isInputRange!R && hasLength!R)
{
    return r.length;
}

//RA range that does not define opDollar
struct S
{
    @property
    {
        enum empty = false;
        int front(){return 1;}
        size_t length(){return 10;}
    }
    void popFront(){}
    int opIndex(size_t i){return i;}
}

void main()
{
    S s;
    writeln(s[$]); //Works
}
//--------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list