November 21st, 2003, 08:26 AM
STL deque problem
I'm novice in STL C++ librari, so my question will be very easy.
I have a structure, for example:
typedef struct _mystruct
} mystruct, *pmystruct;
I can define a class based on queue STL template:
typedef queue<mystruct, list<mystruct> > MEMBERS_QUEUE; // This works perfectly
But I want also define a class based on deque:
typedef deque<mystruct, list<mystruct> > MEMBERS_DEQUE; // This doesn't work.
I suspect that I must define allocator for mystruct... What should I do to construct own class based on deque and mystruct?
November 21st, 2003, 08:51 AM
when you use std::queue as follows:
typedef deque<mystruct > MEMBERS_DEQUE;
you are saying to use a list internally in the std::queue code.
typedef queue<mystruct, list<mystruct> > MEMBERS_QUEUE;
(by default it uses a std::deque). A queue is container
adapter - it takes a standard container, and restricts the
operations that can be done on it (and gives the functions
names that are more appropriate for a queue).
If you wanted the internal container in the queue to
be a deque instead of a list you would use :
or, since deque is used by default ...
typedef queue<mystruct, deque<mystruct> > MEMBERS_DEQUE;
typedef queue<mystruct> MEMBERS_DEQUE;
Click Here to Expand Forum to Full Width