New operators opStaticIndex and friends

Manu turkeyman at gmail.com
Wed May 15 16:20:14 UTC 2019


On Tue, May 14, 2019 at 9:15 AM H. S. Teoh via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
>
> On Tue, May 14, 2019 at 03:49:51PM +0000, Q. Schroll via Digitalmars-d wrote:
> > I whish, D has these operators:
> >
> > opStaticIndex
> > opStaticIndexAssign
> > opStaticIndexOpAssign
> > opStaticSlice
> >
> > When used, they look the same way as opIndex and friends, but the
> > stuff between [ and ] would be bound to template parameters (instead
> > of runtime parameters) and be known at compile time. Basically, this
> > allows to implement static indexing the same way it is possible for an
> > AliasSeq.
>
> +1.  I'd love to have this feature too.

I have wanted this so many times. In C++, we can check if a value is a
literal with some stupid __builtin_whatever() thing, and that can
drive patterns like this, but that's terrible, and this proposal is
obviously the right way to go about it.


More information about the Digitalmars-d mailing list