How templates work (bonus) - Full instantiation of Iota!(1,5)

Stefan Koch uplink.coder at googlemail.com
Thu Jun 4 13:22:52 UTC 2020


On Thursday, 4 June 2020 at 13:21:08 UTC, Stanislav Blinov wrote:
> On Thursday, 4 June 2020 at 11:33:48 UTC, Stefan Koch wrote:
>> As part of my series of templates
>> I have done a a full instantiation of Iota!(1,5).
>> (By hand!)
>> And here is the result:
>>
>> // ...
>>
>> Because it has been done manually there are probably some bugs.
>> Can you find them all?
>
> Is that really full? I.e. you're not counting the 
> instantiations of Seq on purpose? :)
>
> If I understand correctly, the below (basically manually 
> written version of std.meta.aliasSeqOf) would just be Iota!(1, 
> 5) => Iota?
>
> template Iota(size_t first, size_t last) {
>     struct Result {
>         static foreach (i; first .. last)
>             mixin("auto e", i, " = ", i, ";");
>     }
>     enum Iota = Result.init.tupleof;
> }

I cannot answer that right now.
My head is already spinning from the mental exercise.


More information about the Digitalmars-d mailing list