how hash_t toHash() works?

Ivan Kazmenko gassa at mail.ru
Tue Apr 30 10:48:07 PDT 2013


>> -----
>> import std.functional;
>> ...
>> 	RedBlackTree !(MyRecord, binaryFun!"a.key < b.key", true) 
>> cont;
>> ...
>> 	cont = redBlackTree !("a.key < b.key", true, MyRecord) ();
>> -----

> Error: template instance RedBlackTree!(ValueRecord, binaryFun, 
> true) RedBlackTree!(ValueRecord, binaryFun, true) does not 
> match template declaration RedBlackTree(T, alias less = "a < 
> b", bool allowDuplicates = false) if 
> (is(typeof(binaryFun!(less)(T.init, T.init))))
> Error: RedBlackTree!(ValueRecord, binaryFun, true) is used as a 
> type

I am able to reproduce it if I write
  	RedBlackTree !(MyRecord, binaryFun, true)
instead of
  	RedBlackTree !(MyRecord, binaryFun!"a.key < b.key", true)

If you are using a plain regular function instead of "a.key < 
b.key" there, consider the following form:

-----
bool less (T) (auto ref T a, auto ref T b)
{
	return a.key < b.key;
}
...
	RedBlackTree !(MyRecord, less, true) cont;
...
	cont = redBlackTree !(less, true, MyRecord) ();
-----

Note that the straightforward notation does *not* work yet in 
2.062 if you want ref parameters:

-----
bool less (ref MyRecord a, ref MyRecord b)
{
	return a.key < b.key;
}
-----

The current condition of binaryFun is too tight.  So, for now, we 
have to create a non-ref version too to pass it.  See (and 
perhaps comment) the following issue in BugZilla:  
http://d.puremagic.com/issues/show_bug.cgi?id=9513

Ivan Kazmenko.


More information about the Digitalmars-d-learn mailing list