Topic: Why is there no 'queue::top()'?
Author: kuehl@uzwil.informatik.uni-konstanz.de (Dietmar Kuehl)
Date: 1996/01/26 Raw View
Hi,
The three standard classes 'stack', 'priority_queue', and 'queue' can
be seen as classes which provide a sequence of the objects inserted
into them depending on the order of insertation ('stack' and 'queue')
and/or the elements themselves ('priority_queue'). In this respect it
sometimes makes sense to define a template class or function which can
take one of these three classes (or a similar one). However, these
three classes have the function 'push()', 'pop()', 'empty(), and
'size()' in common (in addition to constructors and destructors).
Unfortunately, this subset is normally not sufficient because there is
no way to retrieve an "current" object. For 'stack' and
'priority_queue' a method 'top()' is defined to get the current object
and for 'queue' methods 'front()' and 'back()' are defined. To conform
to the same requirements, it would be necessary for all three classes
to share a common method (e.g. 'top()') to retrieve the current
element. A suitable implementation of 'queue::top()' would be to return
'queue::front()' (this is what a queue normally defines as the current
object).
Why is this 'queue::top() missing? Was it intentional? If so, what are
the reasons and the suggested technic to work around the missing
method?
--
dietmar.kuehl@uni-konstanz.de
http://www.informatik.uni-konstanz.de/~kuehl
I am a realistic optimist - that's why I appear to be slightly pessimistic
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]