The following code does not compile, because the custom predicate of std.algorithm.sort is a template parameter, and therefore can only be a function, but not a delegate. In C++, there is a variant of sort taking a function-object as a second (run-time) parameter, but phobos does not seems to have such a thing. It seems like a pretty common problem to me, so does anyone have a solution?


class Foo
{
  int[] order;

  bool cmp(int a, int b) const
  {
    return order[a] < order[b];
  }
}

void main()
{
  auto f = new Foo;
  int[] data;
  sort!(f.cmp)(data);
}

Reply via email to