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);
}
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?
- sort using delegate as predicate via Digitalmars-d-learn
- Re: sort using delegate as predi... Justin Whear via Digitalmars-d-learn
- Re: sort using delegate as predi... H. S. Teoh via Digitalmars-d-learn
- Re: sort using delegate as predi... via Digitalmars-d-learn
- Re: sort using delegate as p... H. S. Teoh via Digitalmars-d-learn
- Re: sort using delegate as p... Justin Whear via Digitalmars-d-learn
