Thread View: comp.std.c++
1 messages
1 total messages
Started by Dietmar Kuehl
Fri, 26 Jan 1996 17:33
Why is there no 'queue::top()'?
Author: Dietmar Kuehl
Date: Fri, 26 Jan 1996 17:33
Date: Fri, 26 Jan 1996 17:33
31 lines
2365 bytes
2365 bytes
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. ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads