Topic: Possible inconsistency in queue in N2284
Author: Chris Jefferson <4zumanga@gmail.com>
Date: Fri, 6 Jul 2007 13:40:49 CST Raw View
I've been looking through N2284 and was looking at queue on page 672
and found some strange inconsistencies.
In operator=(queue&&q), std::move(q.c) is write. Later in
swap(queue&&q), the "std::move" is missing. Seeing as most containers
require a move-aware swap, I don't understand why there is a move in
one place and not in the other.
Further, in push(value_type&& x), why write std::move(x)? surely this
should be a no-op?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: howard.hinnant@gmail.com (Howard Hinnant)
Date: Fri, 6 Jul 2007 22:23:08 GMT Raw View
All three look ok to me. Details below:
In article <1183735349.996640.180410@n60g2000hse.googlegroups.com>,
Chris Jefferson <4zumanga@gmail.com> wrote:
> I've been looking through N2284 and was looking at queue on page 672
> and found some strange inconsistencies.
>
> In operator=(queue&&q), std::move(q.c) is write.
Right. The std::move is needed because q.c is an lvalue that needs to
be cast to an rvalue.
> Later in
> swap(queue&&q), the "std::move" is missing. Seeing as most containers
> require a move-aware swap, I don't understand why there is a move in
> one place and not in the other.
In the case of operator= one wants to perform a different operation
depending on whether the rhs is an lvalue or rvalue (one's allowed to
modify the rhs and the other isn't). In the case of swap, we're saying:
we don't care whether the rhs is an lvalue or rvalue, accept either and
do the same algorithm.
> Further, in push(value_type&& x), why write std::move(x)? surely this
> should be a no-op?
Inside of push(value_type&& x), x is an lvalue. We want to forward x as
an rvalue to c.push_back, so the std::move is necessary.
-Howard
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]