user3233447
user3233447

Reputation: 21

priority queue with a list container

I'm trying to use a list as the underlying container for a priority queue that is holding datanode objects. It seems to work fine using a vector or deque, but i try to use a list as the underlying container and i try to push something onto the queue i get the error :

Error 3 error C2784: 'unknown-type std::operator -(std::move_iterator<_RanIt> &,const std::move_iterator<_RanIt2> &)' : could not deduce template argument for 'std::move_iterator<_RanIt> &' from 'std::_List_unchecked_iterator>>'

struct datanode{
    int depth;
    int cost;
    const int SIZE = 10;
    int ident[9];   
    int parent;
    datanode(int dep, int id[9], int);
    datanode(int dep, int id[9], int, int);
    datanode(const datanode&);
    datanode(); 
    datanode& datanode::operator=(const datanode&);
};

class NodeComparison
{
  public:
    bool operator() (datanode& da, datanode& db)
    {
        return da.cost > db.cost;
    }
};

int main(){
    std::priority_queue<datanode,list<datanode>, NodeComparison> PQueue;
    int a[10] = {1,2,3,4,5,6,7,8,9,10};
    datanode d(0,a,0);
    PQueue.push(d);
 }

Upvotes: 1

Views: 2106

Answers (1)

T.C.
T.C.

Reputation: 137414

§23.6.4 [priority.queue]/p1:

Any sequence container with random access iterator and supporting operations front(), push_back() and pop_back() can be used to instantiate priority_queue.

std::list doesn't have random access iterators.

Upvotes: 9

Related Questions