how hash_t toHash() works?
gedaiu
szabobogdan at yahoo.com
Sat May 4 13:25:44 PDT 2013
On Tuesday, 30 April 2013 at 17:48:08 UTC, Ivan Kazmenko wrote:
>>> -----
>>> 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.
One more question... why associative arrays in D can't be
implemented like here?
http://svn.php.net/viewvc/php/php-src/trunk/Zend/zend_hash.h?view=markup
it seems that php arrays uses hash tables too but they preserve
orders.
Thanks,
Bogdan
More information about the Digitalmars-d-learn
mailing list