aBothe / Mono-D

D Add-In for MonoDevelop
http://wiki.dlang.org/Mono-D
Other
113 stars 26 forks source link

Provide auto-completion for types constrained to be a range #537

Open Orvid opened 10 years ago

Orvid commented 10 years ago

It would be nice if with the following code, wtr was typed such that it had the members expected of an output range of chars:

void mangleTo(OR)(OR wtr)
    if (isOutputRange!(OR, char))
{
}

This would make writing range-based code much easier.

aBothe commented 10 years ago

So.. Type induction? I kinda thought about this earlier, but yeah, I guess this should be realizable. In..some ways I don't even know yet :D

Orvid commented 10 years ago

yep :D

aBothe commented 10 years ago

I guess this simply can't be induced in any way and thus must be hardcoded or so:

template isOutputRange(R, E)
{
    enum bool isOutputRange = is(typeof(
    (inout int = 0)
    {
        R r = R.init;
        E e = E.init;
        put(r, e);
    }));
}

Really gotta wonder why they all won't use normal OOP to make their lifes easier...

aBothe commented 10 years ago

Gosh, editing std.range sucks..but which benefits coming from an IDE are there anyway for handcrafted code like this.

Orvid commented 10 years ago

The feature I'm suggesting isn't intended for editing code that defines a range; rather, it's for code that uses ranges either as input or output to the function.

aBothe commented 10 years ago

Hold on, I've got a better idea: I won't deduce isOutputRange!... but only resolve the primary symbol isOutputRange. Then I look around for symbol definitions that have isOutputRange in their constraints as well, so I could build up an artificial type declaration.

Orvid commented 10 years ago

Yep, that would be perfect.

Orvid commented 10 years ago

To reduce the amount of hard-coding required, it should be possible to extract the information you need by parsing std.range.dummyRanges and instantiating it for the particular uses.