Re: How to define and use a custom comparison function

2014-06-17 Thread TheFlyingFiddle via Digitalmars-d-learn
On Tuesday, 17 June 2014 at 07:53:51 UTC, monarch_dodra wrote: On Tuesday, 17 June 2014 at 04:32:20 UTC, Jakob Ovrum wrote: On Monday, 16 June 2014 at 20:49:29 UTC, monarch_dodra wrote: MyCompare cmp(SortOrder.ASC, 10); This syntax is not valid D. It should be: auto cmp = MyCompare(SortO

Re: How to define and use a custom comparison function

2014-06-17 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 17 June 2014 at 04:32:20 UTC, Jakob Ovrum wrote: On Monday, 16 June 2014 at 20:49:29 UTC, monarch_dodra wrote: MyCompare cmp(SortOrder.ASC, 10); This syntax is not valid D. It should be: auto cmp = MyCompare(SortOrder,ASC, 10); Well, techincally, the *syntax* is valid. If "

Re: How to define and use a custom comparison function

2014-06-16 Thread Jakob Ovrum via Digitalmars-d-learn
On Tuesday, 17 June 2014 at 04:32:20 UTC, Jakob Ovrum wrote: On Monday, 16 June 2014 at 20:49:29 UTC, monarch_dodra wrote: MyCompare cmp(SortOrder.ASC, 10); This syntax is not valid D. It should be: auto cmp = MyCompare(SortOrder,ASC, 10); Sorry, that first comma is a typo and should b

Re: How to define and use a custom comparison function

2014-06-16 Thread Jakob Ovrum via Digitalmars-d-learn
On Monday, 16 June 2014 at 20:49:29 UTC, monarch_dodra wrote: MyCompare cmp(SortOrder.ASC, 10); This syntax is not valid D. It should be: auto cmp = MyCompare(SortOrder,ASC, 10);

Re: How to define and use a custom comparison function

2014-06-16 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 16 June 2014 at 09:24:22 UTC, Marc Schütz wrote: You can pass anything to the sort function that's callable, including an object: struct MyCompare { SortOrder order; int column; bool opCall(const ref DataRow lhs, const ref DataRow rhs) { retu

Re: How to define and use a custom comparison function

2014-06-16 Thread via Digitalmars-d-learn
You can pass anything to the sort function that's callable, including an object: struct MyCompare { SortOrder order; int column; bool opCall(const ref DataRow lhs, const ref DataRow rhs) { return order == SortOrder.ASC ? lhs[column] < rhs

How to define and use a custom comparison function

2014-06-15 Thread belkin via Digitalmars-d-learn
I am new to D so I am probably not using the right terminology but here is a piece of C++ code (not complete) that I would like to translate to idiomatic D. I have defined a function object that I pass to std::sort to std:map as follows: enum class SortOrder{ ASC, DESC }; typedef std::vector D