View source code
Display the source code in std/traits.d from which this page was generated on
github.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Alias std.traits.ForeachType
Returns the inferred type of the loop variable when a variable of type T
is iterated over using a foreach
loop with a single loop variable and
automatically inferred return type. Note that this may not be the same as
std.range.ElementType!Range
in the case of narrow strings, or if T
has both opApply and a range interface.
Declaration
alias ForeachType(T) = ReturnType!(typeof((inoutintx=0){foreach(elem;T.init){returnelem;}assert(0);}))
;
Example
static assert(is(ForeachType!(uint[]) == uint)); static assert(is(ForeachType!string == immutable(char))); static assert(is(ForeachType!(string[string]) == string)); static assert(is(ForeachType!(inout(int)[]) == inout(int)));
Authors
Walter Bright,
Tomasz Stachowiak (
),
Andrei Alexandrescu,
Shin Fujishiro,
Robert Clipsham,
David Nadlinger,
Kenji Hara,
Shoichi Kato
isExpressions