On Fri, 31 Jul 2015 15:17:10 -0400
Victor Bazarov <v.ba...@comcast.invalid> wrote:
> On 7/31/2015 2:55 PM, Scott Lurndal wrote:
[snip]
It is enough in the sense that it provides an alternative to the OP's
incorrect use of empty(), which is a design error if concurrent access
to the stack object is to be provided.
Here the pop() method takes a non-const reference argument, presumably
as an out parameter, which means that no separate empty() or front()
methods are either needed or desirable. In this approach, pop() either
extracts the item at the top of the stack (if any) as a value and
assigns it to obj, or throws an exception, and it does so in a way which
is thread safe and (if the assignment to the obj argument is done
correctly) also strongly exception safe.
As a minor quibble, the push method should have taken a const lvalue
reference argument or rvalue reference argument, and not a non-const
lvalue reference argument.
Chris