: c(std::move(__s)), comp(__x)
{ std::make_heap(c.begin(), c.end(), comp); }
+ priority_queue(const priority_queue&) = default;
+ priority_queue& operator=(const priority_queue&) = default;
+
+ priority_queue(priority_queue&& __q)
+ noexcept(__and_<is_nothrow_move_constructible<_Sequence>,
+ is_nothrow_move_constructible<_Compare>>::value)
+ : c(std::move(__q.c)), comp(std::move(__q.comp))
+ { __q.c.clear(); }
+
+ priority_queue&
+ operator=(priority_queue&& __q)
+ noexcept(__and_<is_nothrow_move_assignable<_Sequence>,
+ is_nothrow_move_assignable<_Compare>>::value)
+ {
+ c = std::move(__q.c);
+ __q.c.clear();
+ comp = std::move(__q.comp);
+ return *this;
+ }
+
template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
explicit
priority_queue(const _Alloc& __a)
template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
priority_queue(priority_queue&& __q, const _Alloc& __a)
- : c(std::move(__q.c), __a), comp(std::move(__q.comp)) { }
+ : c(std::move(__q.c), __a), comp(std::move(__q.comp))
+ { __q.c.clear(); }
#endif
/**
* the copy according to @a __x.
*
* For more information on function objects, see the
- * documentation on @link functors functor base
- * classes@endlink.
+ * documentation on @link functors functor base classes@endlink.
*/
#if __cplusplus < 201103L
template<typename _InputIterator>
--- /dev/null
+// { dg-do run { target c++11 } }
+
+#include <queue>
+#include <vector>
+#include <testsuite_hooks.h>
+
+template<typename T, typename Seq>
+bool
+check(std::priority_queue<T, Seq>& p)
+{
+ if (!p.empty())
+ {
+ T prev = p.top();
+ p.pop();
+ while (!p.empty())
+ {
+ if ( prev < p.top() )
+ return false;
+ prev = p.top();
+ p.pop();
+ }
+ }
+ return true;
+}
+
+// A vector-like type that has a non-empty moved-from state.
+struct Vector : std::vector<int>
+{
+ using Base = std::vector<int>;
+
+ using Base::Base;
+
+ Vector(const Vector&) = default;
+ Vector& operator=(const Vector&) = default;
+
+ Vector(Vector&& v) : Base(static_cast<const Base&>(v))
+ {
+ invalidate_heap(v);
+ }
+
+ Vector(Vector&& v, const std::allocator<int>&)
+ : Base(static_cast<const Base&>(v))
+ {
+ invalidate_heap(v);
+ }
+
+ Vector&
+ operator=(Vector&& v)
+ {
+ static_cast<Base&>(*this) = static_cast<const Base&>(v);
+ invalidate_heap(v);
+ return *this;
+ }
+
+ void invalidate_heap(Base& v) { v = {1,2,3}; }
+};
+
+void
+test_moves()
+{
+ std::priority_queue<int, Vector> p;
+ p.push(1);
+ p.push(3);
+ p.push(5);
+ p.push(2);
+ p.push(2);
+ p.push(2);
+ p.push(2);
+ std::priority_queue<int, Vector> p2 = std::move(p);
+ VERIFY( check(p) );
+
+ // Allocator-extended move constructor:
+ std::priority_queue<int, Vector> p3(std::move(p2), std::allocator<int>());
+ VERIFY( check(p2) );
+
+ p2 = std::move(p3);
+ VERIFY( check(p3) );
+}
+
+int main()
+{
+ test_moves();
+}