No shortcircuit for static if or template constraints?

qsdfghjk via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Oct 24 16:59:00 PDT 2015


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().


More information about the Digitalmars-d-learn mailing list