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

Yep, that works, thanks!


I also found I can do it with __traits, but I think your way is cleaner.

enum bool isSupportedRange(T) = __traits(compiles, isInputRange!T && isIntegral!(ForeachType!T));

cheers,
stew

Reply via email to