Topic: Constructors for priority_queue versus queue and stack


Author: Edward Diener <eldiener@tropicsoft.invalid>
Date: Tue, 9 Mar 2010 02:10:15 CST
Raw View
For the priority_queue container adapter one of the constructors takes
a pair of InputIterators ( along with compare and container parameters
). The queue and stack container adapters do not have such a
constructor.

What is the reason for limiting the queue and stack's constructor in this way ?

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@googlemail.com>
Date: Tue, 9 Mar 2010 05:24:13 CST
Raw View
On Mar 9, 9:10 am, Edward Diener <eldie...@tropicsoft.invalid> wrote:
> For the priority_queue container adapter one of the constructors takes
> a pair of InputIterators ( along with compare and container parameters
> ). The queue and stack container adapters do not have such a
> constructor.
>
> What is the reason for limiting the queue and stack's constructor in this way ?

I do not think that this is a limitation of the latter, but
that the design choice for priority_queue was based
on the history of the STL.
Before move-semantics was added to C++, it was
probably considered to add the range constructors,
because compilers were not that good in inlining code
in these days. priority_queue is particularly different
from the other adaptors, because it is the only one,
that combines another container with an additional
component, the comparer. In this case you cannot
accept the order of elements that would be provided
by an already filled source container, but you must
resort that in any case. Therefore it was probably
assumed that this special constructor would
allow for better optimization choices of this special
situation. Note that priority_queue really deviates
from the basic principles of the adaptor classes
in this regard looking at the first paragraph of
[container.adaptors]:

"The container adaptors each take a Container
template parameter, and each constructor takes
a Container reference argument. [..]."

Therefore I don't really consider it as a defect that
the other adaptors do not provide range c'tors.

HTH & Greetings from Bremen,

Daniel Kr   gler


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]