The following code works for finding the lower bound based on needle. But I have to create a needle which I don't want to do. How can I use lowerBound with just the sortKey, date in this case? So I want to do something like the following - but it won't work. Is there a way to search an array I know is ordered by date by only supplying date?

assumeSorted!q{ a.date < b.date }(sarr)
          .lowerBound(Date(2000,2,1));

Thanks
Dan
-------------------------------------------------------

import std.stdio;
import std.range;
import std.datetime;
import std.algorithm;
import std.array;

struct S {
  Date date;
  string foo;
}

void main() {
  auto sarr = [ S(Date(2000,1,1), "x"),
                S(Date(2000,2,1), "a"),
                S(Date(2000,3,1), "foo") ];
  assert(sort!q{ a.date < b.date }(sarr).array == sarr);

  auto needle = S(Date(2000,2,1));
  writeln(assumeSorted!q{ a.date < b.date }(sarr)
          .lowerBound(needle));

  writeln(sarr);
}


Reply via email to