View source code
Display the source code in std/range.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.
Function std.range.choose
Choose one of two ranges at runtime depending on a Boolean condition
.
The ranges may be different, but they must have compatible element types (i.e.
CommonType
must exist for the two element types). The result is a range
that offers the weakest capabilities of the two (e.g. ForwardRange
if R1
is a random-access range and R2
is a forward range).
Prototype
auto choose(R1, R2)( bool condition, R1 r1, R2 r2 ) if (isInputRange!(Unqual!R1) && isInputRange!(Unqual!R2) && !is(CommonType!(ElementType!(Unqual!R1), ElementType!(Unqual!R2)) == void));
Parameters
Name | Description |
---|---|
condition | which range to choose : if true , otherwise |
r1 | the "true" range |
r2 | the "false" range |
Returns
A range type dependent on R1
and R2
.
Bugs
Authors
Andrei Alexandrescu, David Simcha, and Jonathan M Davis. Credit for some of the ideas in building this module goes to Leonardo Maffi.