www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Templated Binary Search Tree treats class as const, compiler complains

reply Mark <tigchelaarm mymacewan.ca> writes:
Hello,

I re wrote my old BST. This one is far more complete and clean.

However, It fails my final unittest when I try to stick a class 
in as its type.

Link: https://dpaste.dzfl.pl/95e1ae49b25b

Ive done this type of thing before, but it is giving me this 
error:

BinarySearchTree.d(30): Error: function 
BinarySearchTree.BinarySearchTree!(Empty).BinarySearchTree.New 
(Empty item) is not callable using argument types (const(Empty))
BinarySearchTree.d(40): Error: function 
BinarySearchTree.BinarySearchTree!(Empty).BinarySearchTree.New 
(Empty item) is not callable using argument types (const(Empty))
BinarySearchTree.d(574): Error: template instance 
BinarySearchTree.BinarySearchTree!(Empty) error instantiating

the New method is on line 94;

I was looking through the Programming in D book, and can't find 
what this is really telling me.

I have templated Stack and queue classes that don't give me these 
errors??

How do I make the BST accept classes like the one in my test?

I don't deal with const stuff, so I'm not too sure what to look 
for concerning these problems.

I'm still looking in the book/site for answers.

Thanks!
Jan 21
parent reply Mark <tigchelaarm mymacewan.ca> writes:
Just realized that I commented out the creation of the BST

new link: https://dpaste.dzfl.pl/ce620cbee919
Jan 21
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 21.01.2018 21:20, Mark wrote:
 Just realized that I commented out the creation of the BST
 
 new link: https://dpaste.dzfl.pl/ce620cbee919
 
'in' means 'const scope', but it seems you need references that are allowed to mutate the incoming items. Remove the 'in' attribute from the parameters and your problem should disappear.
Jan 21
parent Mark <tigchelaarm mymacewan.ca> writes:
On Sunday, 21 January 2018 at 20:46:56 UTC, Timon Gehr wrote:
 On 21.01.2018 21:20, Mark wrote:
 Just realized that I commented out the creation of the BST
 
 new link: https://dpaste.dzfl.pl/ce620cbee919
 
'in' means 'const scope', but it seems you need references that are allowed to mutate the incoming items. Remove the 'in' attribute from the parameters and your problem should disappear.
Ok, I was looking at the wrong stuff. Looking at varidiac functions in the book, I'm seeing what you're saying. I thought that was used as a keyword for variadic arguments. Thanks, that worked perfectly! Mark.
Jan 21