how hash_t toHash() works?
gedaiu
szabobogdan at yahoo.com
Tue Apr 30 09:54:54 PDT 2013
On Monday, 29 April 2013 at 16:01:15 UTC, Ivan Kazmenko wrote:
>> one more question
>> What is the type of cont?
>>
>> auto cont = redBlackTree !("a.key < b.key", true, MyRecord) ();
>>
>> I want to use this as a property in a class and i can't use
>> there auto keyword... I tried different types but it did not
>> work.
>
> For me, the following declaration works:
>
> -----
> import std.functional;
> ...
> RedBlackTree !(MyRecord, binaryFun!"a.key < b.key", true) cont;
> ...
> cont = redBlackTree !("a.key < b.key", true, MyRecord) ();
> -----
>
> I admit it could have been easier to figure out. For example,
> "writeln (typeof (cont).stringof);" just prints "RedBlackTree"
> which is not enough for a proper declaration. I've inferred
> the right declaration from the following lines in container.d:
>
> -----
> /++ Ditto +/
> auto redBlackTree(alias less, bool allowDuplicates, E)(E[]
> elems...)
> if(is(typeof(binaryFun!less(E.init, E.init))))
> {
> //We shouldn't need to instantiate less here, but for some
> reason,
> //dmd can't handle it if we don't (even though the template
> which
> //takes less but not allowDuplicates works just fine).
> return new RedBlackTree!(E, binaryFun!less,
> allowDuplicates)(elems);
> }
> -----
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
Do you know what this error means?
Thank,
Bogdan
More information about the Digitalmars-d-learn
mailing list