I recently asked about access to the base container of STL adapters . I got a very useful 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 could not understand this line:
return q.*&HackedQueue::c;
What does this line do? In addition, how can this line access a closed container in priority_queue , which is passed to the Container function?
c ++ stl
Arak
source share