clearing a priority_queue

T

Tino

Hopefully a simple question:

What is the best/safest/fastest way to clear/make empty a std::priority_queue?

Thanks,
Ryan
 
V

Victor Bazarov

Tino said:
Hopefully a simple question:

What is the best/safest/fastest way to clear/make empty a
std::priority_queue?

std::priority_queue myqueue;
... // fill it up

// clear it:
myqueue = std::priority_queue(); // assign an empty one to it

Victor
 
T

tom_usenet

std::priority_queue?

std::priority_queue myqueue;
... // fill it up

// clear it:
myqueue = std::priority_queue(); // assign an empty one to it

Doh! I forgot queues are assignable.

Tom
 
R

Ryan Martino

**** Post for FREE via your newsreader at post.usenet.com ****


Victor Bazarov said:
std::priority_queue?

std::priority_queue myqueue;
... // fill it up

// clear it:

When you say "clear it", do you mean that I need to pop off all items? I'm
worried about proper destruction of the elements of the priority_queue. If
this is the case, doesn't

while( myqueue.size() > 0 )
myqueue.pop();

do the job? But is this the fastest way to do it? For std::vector there is
std::vector::clear, and I couldn't find anything analagous for
std::priority_queue.
myqueue = std::priority_queue(); // assign an empty one to it

Victor



-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*** Usenet.com - The #1 Usenet Newsgroup Service on The Planet! ***
http://www.usenet.com
Unlimited Download - 19 Seperate Servers - 90,000 groups - Uncensored
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
S

Stuart Golodetz

Ryan Martino said:
**** Post for FREE via your newsreader at post.usenet.com ****




When you say "clear it", do you mean that I need to pop off all items?

No, he means that clears it (hence the colon).

HTH,

Stuart.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top