opIndex() may hide opSlice()

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Thu Mar 9 21:48:22 PST 2017


On Fri, Mar 10, 2017 at 01:34:13AM +0000, XavierAP via Digitalmars-d wrote:
> On Friday, 10 March 2017 at 01:10:21 UTC, H. S. Teoh wrote:
> > On Fri, Mar 10, 2017 at 01:07:33AM +0000, XavierAP via Digitalmars-d
> > wrote:
> > > 
> > > Should not the overload of opSlice() with no arguments be
> > > deprecated?
> > > Am I missing something?
> > 
> > Using opSlice() for slicing (i.e., arr[]) is old,
> > backward-compatible behaviour.
> 
> Yes but again, why not deprecate it, while still supporting it?
> 
> It could same someone from having their code hidden and replaced in a
> polymorphic scenario. Granted it may not be a likely use case, but the
> situation seems to me to go against D's strong compile-time
> guarantees.

I'm not 100% as I wasn't part of the original discussion, but you could
file an enhancement request to this effect in the bug tracker.  I think
it makes sense to add a warning to the effect that opSlice() without
arguments should be replaced by opIndex() without arguments in the next
release, then turn it into a deprecation in the following release, and
then an error in the one after that.  But there may be some concerns
about this that I'm not aware of.


T

-- 
Chance favours the prepared mind. -- Louis Pasteur


More information about the Digitalmars-d mailing list