isIterable(T)

dsimcha dsimcha at yahoo.com
Sun Apr 26 10:44:31 PDT 2009


I've been thinking a little more about ranges, etc. and it would be nice to
have a template for isIterable(T) that simply tells whether an object can be
iterated over with foreach, without caring how this iteration works (ranges,
opApply, builtin array/AA).  I have some use cases where I'm writing very
generic functionality and all I need is the lowest common denominator that,
given an object T, the following will compile, and to know what type elem
would be:

foreach(elem; T.init) {}

This functionality does not require any of the more advanced features of
ranges, just iteration.  Is there any good way to write a template for this?
Since foreach is a statement, is(typeof()) and __traits(compiles) are out.



More information about the Digitalmars-d mailing list