← Back to team overview

widelands-dev team mailing list archive

troubles with priority_queue

 

Hi,

I spent few hours today to code priority queue for economy. The queue
should contains structs of distance,&supply. Distance is distance from
request to supply and this has to be a sorting key. I tried multiple things
but failed to make it work. By now I have:

---------------------------------------------
struct request_dist {
request_dist(uint32_t d, Supply& s) : dist(d), supply(s) { }
struct compare {
bool operator() (const request_dist & a, const request_dist & b) const {
return a.dist < b.dist;
}

};

       // is following needed?
void operator=(const request_dist& other){
dist = other.dist;
supply = other.supply;
}
uint32_t dist;
Supply& supply;
};



using AvailableSupplies = std::priority_queue<request_dist,
std::vector<request_dist>, request_dist::compare>;
AvailableSupplies available_supplies;

---------------------------------------------

Currently I am getting this:

/var/widelands/request_supply_opt/src/economy/economy.h:253:10: error:
invalid use of incomplete type 'struct Widelands::Supply'
   supply = other.supply;
          ^
In file included from
/var/widelands/request_supply_opt/src/economy/economy.h:34:0,
                 from
/var/widelands/request_supply_opt/src/wui/actionconfirm.cc:25:
/var/widelands/request_supply_opt/src/economy/supply_list.h:30:8: error:
forward declaration of 'struct Widelands::Supply'
 struct Supply;


Can you advice me? This is far beyond my coding skills...

But on the other hand this is not critical for my life nor widelands, I
just have some improvement in my head...

Thanks

Tibor

Follow ups