I asked a question while ago about accessing the underlying container of STL adapters. I got a very helpful answer:
template <class T, class S, class C>
S& Container(priority_queue<T, S, C>& q) {
struct HackedQueue : private priority_queue<T, S, C> {
static S& Container(priority_queue<T, S, C>& q) {
return q.*&HackedQueue::c;
}
};
return HackedQueue::Container(q);
}
int main()
{
priority_queue<SomeClass> pq;
vector<SomeClass> &tasks = Container(pq);
return 0;
}
Unfortunately, I couldn't understand this line:
return q.*&HackedQueue::c;
What does this line do? Also, how could that line access the private container in priority_queue
that is passed to the function Container
?