Why is std.algorithm so complicated to use?

Daniel Murphy yebblies at nospamgmail.com
Tue Jul 10 13:20:31 PDT 2012


"Jonathan M Davis" <jmdavisProg at gmx.com> wrote in message 
news:mailman.249.1341951069.31962.digitalmars-d at puremagic.com...
> On Tuesday, July 10, 2012 21:07:51 Jacob Carlborg wrote:
>> Second, it would be much easier if it would be possible to better name
>> these ranges, something like interfaces but without polymorphism. This
>> as been mentioned several times before.
>
> They're templated types. They have to be templated types. And since 
> they're
> templated types, better names do you no good whatsoever as far as 
> declaring a
> variable goes. You'll _never_ be able to do something like
>
> NiceName range;
>

This isn't really true.  You can still in some cases  the type relative to 
some other type. (warning: old code, may not compile any more)
Sure, you can use auto and typeof, but that doesn't make it clearer.

struct SubSequences(R)
{
    R r;
    R s;
    Take!R c;
    int n;
    this(R r)
    {
        this.r = r;
        s = r;
        n = 0;
        c = take(r, 1);
        popFront();
    }
    void popFront()
    {
        c.popFront();
        if (c.empty)
        {
            c = take(r, ++n);
            s.popFront();
        }
    }
    Take!R front() { return c; }
    bool empty() { return s.empty; }
    typeof(this) save() { return this; }
};
SubSequences!R subSequences(R)(R r) { return SubSequences!R(r); } 




More information about the Digitalmars-d mailing list