Mono-D icon indicating copy to clipboard operation
Mono-D copied to clipboard

Provide auto-completion for types constrained to be a range

Open Orvid opened this issue 11 years ago • 8 comments

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.

Orvid avatar Sep 01 '14 18:09 Orvid

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

aBothe avatar Sep 01 '14 18:09 aBothe

yep :D

Orvid avatar Sep 01 '14 18:09 Orvid

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 avatar Sep 02 '14 10:09 aBothe

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

aBothe avatar Sep 02 '14 10:09 aBothe

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.

Orvid avatar Sep 04 '14 01:09 Orvid

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.

aBothe avatar Sep 04 '14 06:09 aBothe

Yep, that would be perfect.

Orvid avatar Sep 04 '14 06:09 Orvid

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.

Orvid avatar Sep 07 '14 01:09 Orvid