Range Type
Bill Baxter
dnewsgroup at billbaxter.com
Mon Mar 24 16:15:06 PDT 2008
Janice Caron wrote:
> On 24/03/2008, Craig Black <cblack at ara.com> wrote:
>> I still think we don't need that second type. We are talking about D 2.0,
>> so backwards.compatibility is less of an issue. Unless there's a compelling
>> reason for it, it should be opSlice(T, T). I think this makes more sense,
>> and simplifies the syntax.
>
> I agree.
>
> But just to be sure, let's ask the loyal readers of this newsgroup...
> Has anyone here ever used opSlice(T,U), where type T != type U? And if
> so, for what purpose, and could you live without it?
Yes I have. The purpose is to implement custom end-relative ranges.
The end-relative indexes are represented using a struct like so:
struct EndRelative
{
int offset;
}
That plus the __opDollar lets you make your user type accept x[3..$-2].
(And even without the opDollar harck you can make it work with something
like x[3..end-2].)
--bb
More information about the Digitalmars-d
mailing list