std:: vector <int> v;
std:: pop_heap (v. begin(), v. end());
My g++ program tries to pop from an empty heap and dies a horrible death of segmentation violation. I think g++ is at fault; I expected an exception, not a signal.
What do you think?
std:: vector <int> v;
std:: pop_heap (v. begin(), v. end());
My g++ program tries to pop from an empty heap and dies a horrible death of segmentation violation. I think g++ is at fault; I expected an exception, not a signal.
What do you think?
Depends on what the documentation says. If it says that the result is undefined, then the program is entitled to detonate your machine, kill all your goldfish, or start thermonuclear war, and you should just not go there.
yecril71pl wrote:
> My g++ program tries to pop from an empty heap and dies a horrible
> death of segmentation violation. I think g++ is at fault; I expected an
> exception, not a signal.
No. From what I can see from the documentation it does not have a throw
specification
> What do you think?
It says among others:
<quote>
The elements first and last-1 are swapped and first,last-1)
is made into a heap.
</quote>
and since for an empty vector begin() == end() and end() points beyond the
last element of the vector pop_heaping an empty vector will probably create
havoc. (–end() on an empty collection ==> KABOOM?)
–
Ruurd
Simple thing is to test if the container is empty before trying to pop it. Most of the stl has a empty()=bool function call on the containers. To me this is only a common sense practice, especially if I am doing something of filling and emptying randomly.