Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// Determine whether some type can be iterated over using foreach.
- /// Will not evaluate true for types such as tuples where all elements may
- /// not be of the same type.
- enum bool isIterable(alias T) = isIterable!(typeof(T));
- /// ditto
- enum bool isIterable(T) = (
- is(typeof({
- // Must be iterable
- foreach(e; T.init){}
- // Indexes must not be known at compile-time
- // Because if they are, this is a tuple
- static if(is(typeof({foreach(i, e; T.init){}}))){
- foreach(i, e; T.init){
- static assert(!is(typeof({enum x = i;})));
- }
- }
- })) && !is(typeof({
- // Must not be an empty tuple
- foreach(e; T.init){
- static assert(false);
- }
- }))
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement