I'm still messing around with binary heaps. I've successfully
created and used it on the function level but for some reason
when I move it to the class level I get an error. Furthermore,
i'm not entirely sure how to use a binary heap without auto as
the type.
class AStar
{
ReferenceNode[] openListContainer;
auto openList = BinaryHeap!(ReferenceNode[], "a.fScore >
b.fScore")(openListContainer, 0 ); // Error
}
Error 1 Error: template instance
BinaryHeap!(ReferenceNode[],"a.fScore > b.fScore")
BinaryHeap!(ReferenceNode[],"a.fScore > b.fScore") does not match
template declaration BinaryHeap(Store,alias less = "a < b") if
(isRandomAccessRange!(Store) ||
isRandomAccessRange!(typeof(Store.init[]))) C:\Users\CP\Documents\Visual
Studio 2010\Projects\D\STDS\NPC.d 101
However this is ok:
class AStar
{
void RandomFunction()
{
ReferenceNode[] openListContainer;
openListContainer.length = 500;
auto openList = BinaryHeap!(ReferenceNode[], "a.fScore >
b.fScore")(openListContainer, 0 ); //This is ok
}
}
I'd also like to try this, but can't seem to figure it out:
class AStar
{
ReferenceNode[] openListContainer;
auto openList; //no identifier for declarator openlist
this()
{
openListContainer.length = 500;
openList = = BinaryHeap!(ReferenceNode[], "a.fScore >
b.fScore")(openListContainer, 0 );
}
}
If I know what type openList was, after creating the heap, I
could simply use that. I tried using typeid( openList ) to find
out. I got the type being something like:
BinaryHeap!(Referencenode[], "a.fScore > b.fScore") openList;
However trying to use this as the type gives me this error:
Error 1 Error: template instance
BinaryHeap!(ReferenceNode[],"a.fScore > b.fScore")
BinaryHeap!(ReferenceNode[],"a.fScore > b.fScore") does not match
template declaration BinaryHeap(Store,alias less = "a < b") if
(isRandomAccessRange!(Store) ||
isRandomAccessRange!(typeof(Store.init[]))) C:\Users\CP\Documents\Visual
Studio 2010\Projects\D\STDS\NPC.d 101
Error 2 Error: BinaryHeap!(ReferenceNode[],"a.fScore > b.fScore")
is used as a type C:\Users\CP\Documents\Visual Studio
2010\Projects\D\STDS\NPC.d 101
I'm just trying to get a variable called openList to the class
level so it doesn't keep getting initialized everytime the
function is called.
Any ideas on how to work this out?