Indexing with an arbitrary type

Alex via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 3 02:21:13 PDT 2016


On Monday, 1 August 2016 at 16:09:50 UTC, Alex wrote:
> On Monday, 1 August 2016 at 15:51:58 UTC, Jonathan M Davis 
> wrote:
> template isIndexable(I, T)
> {
>     enum isIndexable = __traits(compiles, T.init[I.init]);
> }

As a last question afterwards:
Is it possible to create such an isIndexable template without 
templating over the type T?
something like

template isIndexable(I)
{
     enum isIndexable = __traits(compiles, ???[I.init]);
}

sure, I could use

__traits(compiles, (int[]).init[I.init])

but is this the intended way to go?


More information about the Digitalmars-d-learn mailing list