2007-10-16 Paolo Carlini <pcarlini@suse.de>
+ * include/bits/stl_queue.h (queue<>::queue(_Sequence&&),
+ queue<>::queue(queue&&), queue<>::operator=(queue&&),
+ queue<>::push(value_type&&), queue<>::swap(queue&&),
+ swap(queue<>&, queue<>&), swap(queue<>&&, queue<>&),
+ swap(queue<>&, queue<>&&), priority_queue<>::
+ priority_queue(const _Compare&, _Sequence&&),
+ priority_queue<>::priority_queue(_InputIterator, _InputIterator,
+ const _Compare&, _Sequence&&),
+ priority_queue<>::priority_queue(priority_queue&&),
+ priority_queue<>::operator=(priority_queue&&),
+ priority_queue<>::push(value_type&&),
+ priority_queue<>::swap(priority_queue&&),
+ swap(priority_queue<>&, priority_queue<>&),
+ swap(priority_queue<>&&, priority_queue<>&),
+ swap(priority_queue<>&, priority_queue<>&&)): Add.
+ * include/bits/stl_stack.h (stack<>::stack(_Sequence&&),
+ stack<>::push(value_type&&), stack<>::swap(stack&&),
+ swap(stack<>&, stack<>&), swap(stack<>&&, stack<>&),
+ swap(stack<>&, stack<>&&)): Add.
+ * testsuite/23_containers/queue/moveable.cc: New.
+ * testsuite/23_containers/priority_queue/moveable.cc: Likewise.
+
+2007-10-16 Paolo Carlini <pcarlini@suse.de>
+
* include/ext/vstring.h (__versa_string<>::
__versa_string(__versa_string&&),
__versa_string<>::operator=(__versa_string&&,
/**
* @brief Default constructor creates no elements.
*/
+#ifndef __GXX_EXPERIMENTAL_CXX0X__
explicit
- queue(const _Sequence& __c = _Sequence()) : c(__c) {}
+ queue(const _Sequence& __c = _Sequence())
+ : c(__c) { }
+#else
+ explicit
+ queue(const _Sequence& __c)
+ : c(__c) { }
+
+ explicit
+ queue(_Sequence&& __c = _Sequence())
+ : c(std::move(__c)) { }
+
+ queue(queue&& __q)
+ : c(std::move(__q.c)) { }
+
+ queue&
+ operator=(queue&& __q)
+ {
+ c = std::move(__q.c);
+ return *this;
+ }
+#endif
/**
* Returns true if the %queue is empty.
push(const value_type& __x)
{ c.push_back(__x); }
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ void
+ push(value_type&& __x)
+ { c.push_back(std::move(__x)); }
+#endif
+
/**
* @brief Removes first element.
*
__glibcxx_requires_nonempty();
c.pop_front();
}
- };
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ void
+ swap(queue&& __q)
+ { c.swap(__q.c); }
+#endif
+ };
/**
* @brief Queue equality comparison.
operator>=(const queue<_Tp, _Seq>& __x, const queue<_Tp, _Seq>& __y)
{ return !(__x < __y); }
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ template<typename _Tp, typename _Seq>
+ inline void
+ swap(queue<_Tp, _Seq>& __x, queue<_Tp, _Seq>& __y)
+ { __x.swap(__y); }
+
+ template<typename _Tp, typename _Seq>
+ inline void
+ swap(queue<_Tp, _Seq>&& __x, queue<_Tp, _Seq>& __y)
+ { __x.swap(__y); }
+
+ template<typename _Tp, typename _Seq>
+ inline void
+ swap(queue<_Tp, _Seq>& __x, queue<_Tp, _Seq>&& __y)
+ { __x.swap(__y); }
+#endif
+
/**
* @brief A standard container automatically sorting its contents.
*
/**
* @brief Default constructor creates no elements.
*/
+#ifndef __GXX_EXPERIMENTAL_CXX0X__
explicit
priority_queue(const _Compare& __x = _Compare(),
const _Sequence& __s = _Sequence())
: c(__s), comp(__x)
{ std::make_heap(c.begin(), c.end(), comp); }
+#else
+ explicit
+ priority_queue(const _Compare& __x,
+ const _Sequence& __s)
+ : c(__s), comp(__x)
+ { std::make_heap(c.begin(), c.end(), comp); }
+
+ explicit
+ priority_queue(const _Compare& __x = _Compare(),
+ _Sequence&& __s = _Sequence())
+ : c(std::move(__s)), comp(__x)
+ { std::make_heap(c.begin(), c.end(), comp); }
+#endif
/**
* @brief Builds a %queue from a range.
* documentation on @link s20_3_1_base functor base
* classes@endlink.
*/
+#ifndef __GXX_EXPERIMENTAL_CXX0X__
template<typename _InputIterator>
priority_queue(_InputIterator __first, _InputIterator __last,
const _Compare& __x = _Compare(),
c.insert(c.end(), __first, __last);
std::make_heap(c.begin(), c.end(), comp);
}
+#else
+ template<typename _InputIterator>
+ priority_queue(_InputIterator __first, _InputIterator __last,
+ const _Compare& __x,
+ const _Sequence& __s)
+ : c(__s), comp(__x)
+ {
+ __glibcxx_requires_valid_range(__first, __last);
+ c.insert(c.end(), __first, __last);
+ std::make_heap(c.begin(), c.end(), comp);
+ }
+
+ template<typename _InputIterator>
+ priority_queue(_InputIterator __first, _InputIterator __last,
+ const _Compare& __x = _Compare(),
+ _Sequence&& __s = _Sequence())
+ : c(std::move(__s)), comp(__x)
+ {
+ __glibcxx_requires_valid_range(__first, __last);
+ c.insert(c.end(), __first, __last);
+ std::make_heap(c.begin(), c.end(), comp);
+ }
+
+ priority_queue(priority_queue&& __pq)
+ : c(std::move(__pq.c)), comp(std::move(__pq.comp)) { }
+
+ priority_queue&
+ operator=(priority_queue&& __pq)
+ {
+ c = std::move(__pq.c);
+ comp = std::move(__pq.comp);
+ return *this;
+ }
+#endif
/**
* Returns true if the %queue is empty.
std::push_heap(c.begin(), c.end(), comp);
}
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ void
+ push(value_type&& __x)
+ {
+ c.push_back(std::move(__x));
+ std::push_heap(c.begin(), c.end(), comp);
+ }
+#endif
+
/**
* @brief Removes first element.
*
std::pop_heap(c.begin(), c.end(), comp);
c.pop_back();
}
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ void
+ swap(priority_queue&& __pq)
+ {
+ using std::swap;
+ c.swap(__pq.c);
+ swap(comp, __pq.comp);
+ }
+#endif
};
// No equality/comparison operators are provided for priority_queue.
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ template<typename _Tp, typename _Sequence, typename _Compare>
+ inline void
+ swap(priority_queue<_Tp, _Sequence, _Compare>& __x,
+ priority_queue<_Tp, _Sequence, _Compare>& __y)
+ { __x.swap(__y); }
+
+ template<typename _Tp, typename _Sequence, typename _Compare>
+ inline void
+ swap(priority_queue<_Tp, _Sequence, _Compare>&& __x,
+ priority_queue<_Tp, _Sequence, _Compare>& __y)
+ { __x.swap(__y); }
+
+ template<typename _Tp, typename _Sequence, typename _Compare>
+ inline void
+ swap(priority_queue<_Tp, _Sequence, _Compare>& __x,
+ priority_queue<_Tp, _Sequence, _Compare>&& __y)
+ { __x.swap(__y); }
+#endif
+
_GLIBCXX_END_NAMESPACE
#endif /* _STL_QUEUE_H */
/**
* @brief Default constructor creates no elements.
*/
+#ifndef __GXX_EXPERIMENTAL_CXX0X__
explicit
stack(const _Sequence& __c = _Sequence())
: c(__c) { }
+#else
+ explicit
+ stack(const _Sequence& __c)
+ : c(__c) { }
+
+ explicit
+ stack(_Sequence&& __c = _Sequence())
+ : c(std::move(__c)) { }
+#endif
/**
* Returns true if the %stack is empty.
push(const value_type& __x)
{ c.push_back(__x); }
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ void
+ push(value_type&& __x)
+ { c.push_back(std::move(__x)); }
+#endif
+
/**
* @brief Removes first element.
*
__glibcxx_requires_nonempty();
c.pop_back();
}
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ void
+ swap(stack&& __s)
+ { c.swap(__s.c); }
+#endif
};
/**
operator>=(const stack<_Tp, _Seq>& __x, const stack<_Tp, _Seq>& __y)
{ return !(__x < __y); }
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ template<typename _Tp, typename _Seq>
+ inline void
+ swap(stack<_Tp, _Seq>& __x, stack<_Tp, _Seq>& __y)
+ { __x.swap(__y); }
+
+ template<typename _Tp, typename _Seq>
+ inline void
+ swap(stack<_Tp, _Seq>&& __x, stack<_Tp, _Seq>& __y)
+ { __x.swap(__y); }
+
+ template<typename _Tp, typename _Seq>
+ inline void
+ swap(stack<_Tp, _Seq>& __x, stack<_Tp, _Seq>&& __y)
+ { __x.swap(__y); }
+#endif
+
_GLIBCXX_END_NAMESPACE
#endif /* _STL_STACK_H */
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2007 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+// NOTE: This makes use of the fact that we know how moveable
+// is implemented on vector (via swap). If the implementation changed
+// this test may begin to fail.
+
+#include <queue>
+#include <utility>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::priority_queue<int> a,b;
+ a.push(1);
+ b = std::move(a);
+ VERIFY( b.size() == 1 && b.top() == 1 && a.size() == 0 );
+
+ std::priority_queue<int> c(std::move(b));
+ VERIFY( c.size() == 1 && c.top() == 1 );
+ VERIFY( b.size() == 0 );
+}
+
+int main(void)
+{
+ test01();
+ return 0;
+}
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2007 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+// NOTE: This makes use of the fact that we know how moveable
+// is implemented on vector (via swap). If the implementation changed
+// this test may begin to fail.
+
+#include <queue>
+#include <utility>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::queue<int> a,b;
+ a.push(1);
+ b = std::move(a);
+ VERIFY( b.size() == 1 && b.front() == 1 && a.size() == 0 );
+
+ std::queue<int> c(std::move(b));
+ VERIFY( c.size() == 1 && c.front() == 1 );
+ VERIFY( b.size() == 0 );
+}
+
+int main(void)
+{
+ test01();
+ return 0;
+}