So, it would seem that the segregation of .top and .pop in stack is no longer needed to be so strict in C++11.
Maybe I am missing something, but the problem in C++03 and previous was that if .pop were to return a value, there was a danger the copy operation could throw an exception during the element copy. Example (code sample taken from here):
template <class T>
// T must have default ctor and copy assignment
class Stack
{
public:
Stack();
~Stack();
Stack(const Stack&);
Stack& operator=(const Stack&);
unsigned Count(); // returns # of T's in the stack
void Push(const T&);
T Pop(); // if empty, returns default-
// constructed T
T Top(); // For backwards compatibility
//
private:
T* v_; // pointer to a memory area big
// enough for 'vsize_' T objects
unsigned vsize_; // the size of the 'v_' area
unsigned vused_; // the number of T's actually
// used in the 'v_' area
};
If you are to do this:
int main(){
Stack<vector<double>> stack;
fill_stack(stack); //fill stack with huge vectors
stack.pop(); //danger of exception being throw from low memory
}
In C++11 this problem goes entirely away since the element can be moved from the stack, entirely eliminating the exception safety concern. That is under the presumption that the element is movable and that the move operation will not throw.
So, my question boils down to, is there a real concert to safety exception concern if .pop were to return the element via move semantics?