View source code
Display the source code in std/algorithm/searching.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
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.

std.algorithm.searching.Until/until - multiple declarations

Function until

Lazily iterates range until the element e for which pred(e, sentinel) is true.

Until!(pred,Range,Sentinel) until(alias pred, Range, Sentinel) (
  Range range,
  Sentinel sentinel,
  OpenRight openRight = Yes.openRight
)
if (!is(Sentinel == OpenRight));

Until!(pred,Range,void) until(alias pred, Range) (
  Range range,
  OpenRight openRight = Yes.openRight
);

This is similar to takeWhile in other languages.

Parameters

NameDescription
pred Predicate to determine when to stop.
range The input range to iterate over.
sentinel The element to stop at.
openRight Determines whether the element for which the given predicate is true should be included in the resulting range (No.openRight), or not (Yes.openRight).

Returns

An input range that iterates over the original range's elements, but ends when the specified predicate becomes true. If the original range is a forward range or higher, this range will be a forward range.

Example

import std.algorithm.comparison : equal;
import std.typecons : No;
int[] a = [ 1, 2, 4, 7, 7, 2, 4, 7, 3, 5];
assert(equal(a.until(7), [1, 2, 4]));
assert(equal(a.until(7, No.openRight), [1, 2, 4, 7]));

Struct Until

Lazily iterates range until the element e for which pred(e, sentinel) is true.

struct Until(alias pred, Range, Sentinel)
  
if (isInputRange!Range);

This is similar to takeWhile in other languages.

Constructors

NameDescription
this (input, sentinel, openRight)

Properties

NameTypeDescription
empty[get] bool
front[get] auto
save[get] Until

Methods

NameDescription
popFront ()

Parameters

NameDescription
pred Predicate to determine when to stop.
range The input range to iterate over.
sentinel The element to stop at.
openRight Determines whether the element for which the given predicate is true should be included in the resulting range (No.openRight), or not (Yes.openRight).

Returns

An input range that iterates over the original range's elements, but ends when the specified predicate becomes true. If the original range is a forward range or higher, this range will be a forward range.

Example

import std.algorithm.comparison : equal;
import std.typecons : No;
int[] a = [ 1, 2, 4, 7, 7, 2, 4, 7, 3, 5];
assert(equal(a.until(7), [1, 2, 4]));
assert(equal(a.until(7, No.openRight), [1, 2, 4, 7]));

Authors

Andrei Alexandrescu

License

Boost License 1.0.