Access template parameters at runtime

Timon Gehr timon.gehr at gmx.ch
Fri Aug 10 14:21:38 PDT 2012


On 08/10/2012 11:09 PM, Dmitry Olshansky wrote:
> On 11-Aug-12 00:58, Andrej Mitrovic wrote:
>> On 8/10/12, jerro <a at a.com> wrote:
>>> This would be one way to do it:
>>
>>
>> On 8/10/12, Christophe Travert <travert at phare.normalesup.org> wrote:
>>> For example:
>>
>> Guys I think you're overcomplecating it, you can just do:
>>
>> struct SomeStruct(integers...)
>> {
>>      enum ints = [integers];
>>      int opIndex(size_t idx) /* ... */
>>      {
>>          return ints[idx];
>>      }
>> }
>>
>> enum or static both work.
>
> Internally identical to:
>
> int opIndex(size_t idx)
> {
>      return [integers][idx];
> }
>
> Allocates on every call or not? I've no idea maybe Kenji fixed this
> already.
>
>
> --
> Dmitry Olshansky

Still allocates in 2.060. static is the keyword of choice.


More information about the Digitalmars-d mailing list