Run-time Indexing of a Compile-Time Tuple
John Colvin via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue May 12 02:27:14 PDT 2015
On Tuesday, 12 May 2015 at 09:26:07 UTC, John Colvin wrote:
> On Monday, 11 May 2015 at 22:46:00 UTC, Per Nordlöw wrote:
>> The pattern
>>
>> final switch (_index)
>> {
>> import std.range: empty, front;
>> foreach (i, R; Rs)
>> {
>> case i:
>> assert(!source[i].empty);
>> return source[i].front;
>> }
>> }
>>
>> occurring in roundRobin() and now also in my merge at
>>
>> https://github.com/nordlow/justd/blob/master/range_ex.d#L604
>>
>> is nor pretty nor concise.
>>
>> Is there a better way of indexing a compile time tuple with a
>> run-time index?
>>
>> It may have to work together with CommonType somehow as is
>> shown in my implementation of merge().
>
> I wrote that code in roundRobin to replace a nightmare string
> mixin. I can't see any way of getting around it, as there is no
> meaningful CommonType for a tuple of arbitrary ranges. The body
> of each case statement needs to know the index at compile-time.
Correction: there are ways around it, but none of them are
improvements.
More information about the Digitalmars-d-learn
mailing list