Container adaptor - missing container support operation

69 views
Skip to first unread message

Akira Takahashi

unread,
Apr 24, 2012, 2:03:54 PM4/24/12
to
Hi,

I read N3337's Container adaptors specification.
I think missing support operation : emplace_back().

23.6.3.1 queue definition
Any sequence container supporting operations front(), back(),
push_back() and pop_front() can be used to instantiate queue.

=> add emplace_back().


23.6.4 Class template priority_queue
Any sequence container with random access iterator and supporting
operations front(), push_back() and pop_back() can be used to
instantiate priority_queue.

=> add emplace_back().


23.6.5 Class template stack
Any sequence container supporting operations back(), push_back() and
pop_back() can be used to instantiate stack.

=> add emplace_back().


Regards,
Akira


--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp...@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]

Daniel Krügler

unread,
Apr 25, 2012, 4:56:05 PM4/25/12
to
Am 24.04.2012 20:03, schrieb Akira Takahashi:
> I read N3337's Container adaptors specification.
> I think missing support operation : emplace_back().
>
> 23.6.3.1 queue definition
> Any sequence container supporting operations front(), back(),
> push_back() and pop_front() can be used to instantiate queue.
>
> => add emplace_back().
>
>
> 23.6.4 Class template priority_queue
> Any sequence container with random access iterator and supporting
> operations front(), push_back() and pop_back() can be used to
> instantiate priority_queue.
>
> => add emplace_back().
>
>
> 23.6.5 Class template stack
> Any sequence container supporting operations back(), push_back() and
> pop_back() can be used to instantiate stack.
>
> => add emplace_back().

I agree that adding these would seem to be more appropriate, even though
the current state does not really look like a defect to me, because
above quoted parts are more like introductory descriptions, not strong
requirements (but the latter following argumentation of mine is moving
slightly on this position). Strictly speaking, not even front() or
push_back (for example) are necessary when such a *container* adaptor is
instantiated.

Based on the same arguments you could argue that you need to add
operator<,>,<=, and>= as well, which are (now) optional as well.

I tend to say that the current wording state is better than adding these
or even further requirements because this would invalidate *existing*
user-provided C++03 sequence containers to be adapted. Consider a very
strict library implementation which considers these wordings as binding
requirements: It might add static assertions to the class body of these
adaptors to ensure that above functions exist: It would be a bad idea to
break existing adaptions that do not provide these functions.

Just my opinion - HTH& Greetings from Bremen,

Daniel Krügler

Jason McKesson

unread,
Apr 25, 2012, 4:56:33 PM4/25/12
to
On Tuesday, April 24, 2012 11:03:54 AM UTC-7, Akira Takahashi wrote:
> Hi,
>
> I read N3337's Container adaptors specification.
> I think missing support operation : emplace_back().
>
> 23.6.3.1 queue definition
> Any sequence container supporting operations front(), back(),
> push_back() and pop_front() can be used to instantiate queue.
>
> => add emplace_back().
>
>
> 23.6.4 Class template priority_queue
> Any sequence container with random access iterator and supporting
> operations front(), push_back() and pop_back() can be used to
> instantiate priority_queue.
>
> => add emplace_back().
>
>
> 23.6.5 Class template stack
> Any sequence container supporting operations back(), push_back() and
> pop_back() can be used to instantiate stack.
>
> => add emplace_back().
>
>
> Regards,
> Akira
>
>

All of those containers have "emplace" functions, which does the same thing. You can only push into one place on the adapters, so "_back" is meaningless.

Nevin ":-]" Liber

unread,
Apr 25, 2012, 6:44:17 PM4/25/12
to
In article
<60068140-4f4a-434e...@g6g2000pbq.googlegroups.com>,
Akira Takahashi <faitha...@gmail.com> wrote:

> Hi,
>
> I read N3337's Container adaptors specification.
> I think missing support operation : emplace_back().

The adaptors all have emplace methods in C++11. Why is that not
sufficient?

--
Nevin ":-)" Liber <mailto:ne...@eviloverlord.com>

Jason McKesson

unread,
Apr 26, 2012, 2:07:22 PM4/26/12
to
On Wednesday, April 25, 2012 3:44:17 PM UTC-7, Nevin :-] Liber wrote:
> > Hi,
> >
> > I read N3337's Container adaptors specification.
> > I think missing support operation : emplace_back().
>
> The adaptors all have emplace methods in C++11. Why is that not
> sufficient?
>
> --
> Nevin ":-)" Liber<mailto:ne...@eviloverlord.com>

Actually, I realized after I replied that he's talking about the *requirements* of the base container. That is, `std::stack::emplace` is supposed to call `emplace_back` on the container, right? But the requirements on the `std::stack` container doesn't say that `emplace_back` is *required*. And you can't call functions on something that you didn't require to actually have those functions.


--

Akira Takahashi

unread,
Apr 26, 2012, 2:07:42 PM4/26/12
to
> You can only push into one place on the adapters, so "_back" is meaningless.

I think all container-adaptor requires "emplace_back" not "emplace".
Your approach is "emplace(c.end(), args...);" ?

Akira Takahashi

unread,
Apr 27, 2012, 2:12:21 PM4/27/12
to
> But the requirements on the `std::stack` container doesn't say that `emplace_back` is *required*. And you can't call functions on something that you didn't require to actually have those functions.

I see.
I understand, container-adaptor's member function template is optional
support operation.
Right?
Reply all
Reply to author
Forward
0 new messages