No shortcircuit for static if or template constraints?

qsdfghjk via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Oct 24 17:01:53 PDT 2015


On Saturday, 24 October 2015 at 23:59:02 UTC, qsdfghjk wrote:
> On Saturday, 24 October 2015 at 23:34:19 UTC, stewart wrote:
>> On Saturday, 24 October 2015 at 23:26:09 UTC, stewart wrote:
>>> [...]
>>
>>
>> Oh and the workaround I'm using is this:
>>
>> ---
>> void func(T)(T vals) {
>>     static if(isInputRange!T) {
>>         static if(isIntegral!(ForeachType!T)) {
>>             // Do something with range
>>         }
>>     } else {
>>         // do something with scalar
>>     }
>> }
>> ---
>>
>> which is a bit ugly.
>
> Maybe this could work:
>
> ---
> enum isSupportedRange(T) = isInputRange!T && is(ForeachType!T) 
> && (isIntegral!(ElementType!T));
> ---
>
> ElementType() should return exactly what you excpeted with 
> ForeachType().

Oh no! there's been a copy & paste error. I actually meant:

---
enum isSupportedRange(T) = isInputRange!T  && 
(isIntegral!(ElementType!T));


More information about the Digitalmars-d-learn mailing list