How to define and use a custom comparison function

TheFlyingFiddle via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 17 12:18:11 PDT 2014


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(SortOrder,ASC, 10);
>
> Well, techincally, the *syntax* is valid. If "MyCompare" 
> contains a constructor, it's legit code to boot. It's part of 
> the uniform initialization syntax, and it's what allows things 
> like:
>
> BigInt b = 5;
>   or
> BigInt b(5);
>
> THAT said, yeah, the MyCompare I posted did not contain a 
> constructor. SO my code was wrong, guilty as charged.

Since when is that syntax valid? Is there somewhere it is 
documented?




More information about the Digitalmars-d-learn mailing list