+2010-02-01 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * include/bits/forward_list.h (forward_list<>::resize(size_type),
+ forward_list(size_type)): Only declare.
+ * include/bits/forward_list.tcc (forward_list<>::resize(size_type),
+ forward_list(size_type)): Define, don't assume CopyConstructible.
+ * testsuite/23_containers/forward_list/cons/10.cc: New.
+ * testsuite/23_containers/forward_list/modifiers/6.cc: Likewis.
+ * testsuite/23_containers/forward_list/requirements/dr438/
+ assign_neg.cc: Adjust dg-error line numbers.
+ * testsuite/23_containers/forward_list/requirements/dr438/
+ insert_neg.cc: Likewise.
+ * testsuite/23_containers/forward_list/requirements/dr438/
+ constructor_1_neg.cc: Likewise.
+ * testsuite/23_containers/forward_list/requirements/dr438/
+ constructor_2_neg.cc: Likewise.
+
+ * include/bits/forward_list.h: Use _M_get_Node_allocator throughout.
+
2010-01-31 Paolo Carlini <paolo.carlini@oracle.com>
* testsuite/23_containers/array/requirements/exception/
{ }
/**
- * @brief Creates a %forward_list with copies of the default element
- * type.
+ * @brief Creates a %forward_list with default constructed elements.
* @param n The number of elements to initially create.
*
- * This constructor fills the %forward_list with @a n copies of
- * the default value.
+ * This constructor creates the %forward_list with @a n default
+ * constructed elements.
*/
explicit
- forward_list(size_type __n)
- : _Base()
- { _M_fill_initialize(__n, value_type()); }
+ forward_list(size_type __n);
/**
* @brief Creates a %forward_list with copies of an exemplar element.
* object used by @a list.
*/
forward_list(const forward_list& __list)
- : _Base(__list.get_allocator())
+ : _Base(__list._M_get_Node_allocator())
{ _M_initialize_dispatch(__list.begin(), __list.end(), __false_type()); }
/**
iterator
insert_after(const_iterator __pos, size_type __n, const _Tp& __val)
{
- forward_list __tmp(__n, __val, this->get_allocator());
+ forward_list __tmp(__n, __val, this->_M_get_Node_allocator());
splice_after(__pos, std::move(__tmp));
return iterator(__const_pointer_cast<typename _Node_base::_Pointer>
(__pos._M_node));
insert_after(const_iterator __pos,
_InputIterator __first, _InputIterator __last)
{
- forward_list __tmp(__first, __last, this->get_allocator());
+ forward_list __tmp(__first, __last, this->_M_get_Node_allocator());
splice_after(__pos, std::move(__tmp));
return iterator(__const_pointer_cast<typename _Node_base::_Pointer>
(__pos._M_node));
iterator
insert_after(const_iterator __pos, std::initializer_list<_Tp> __il)
{
- forward_list __tmp(__il, this->get_allocator());
+ forward_list __tmp(__il, this->_M_get_Node_allocator());
splice_after(__pos, std::move(__tmp));
return iterator(__const_pointer_cast<typename _Node_base::_Pointer>
(__pos._M_node));
* This function will %resize the %forward_list to the specified
* number of elements. If the number is smaller than the
* %forward_list's current size the %forward_list is truncated,
- * otherwise the %forward_list is extended and new elements are
- * populated with given data.
+ * otherwise the %forward_list is extended and the new elements
+ * are default constructed.
*/
void
- resize(size_type __sz)
- { resize(__sz, _Tp()); }
+ resize(size_type __sz);
/**
* @brief Resizes the %forward_list to the specified number of
// <forward_list.tcc> -*- C++ -*-
-// Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+// Copyright (C) 2008, 2009, 2010 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
}
}
+ template<typename _Tp, typename _Alloc>
+ forward_list<_Tp, _Alloc>::
+ forward_list(size_type __n)
+ : _Base()
+ {
+ typename _Node_base::_Pointer __to = &this->_M_impl._M_head;
+ for (; __n > 0; --__n)
+ {
+ __to->_M_next = this->_M_create_node();
+ __to = __to->_M_next;
+ }
+ }
+
template<typename _Tp, typename _Alloc>
forward_list<_Tp, _Alloc>&
forward_list<_Tp, _Alloc>::
return *this;
}
+ template<typename _Tp, typename _Alloc>
+ void
+ forward_list<_Tp, _Alloc>::
+ resize(size_type __sz)
+ {
+ iterator __k = before_begin();
+
+ size_type __len = 0;
+ while (__k._M_next() != end() && __len < __sz)
+ {
+ ++__k;
+ ++__len;
+ }
+ if (__len == __sz)
+ erase_after(__k, end());
+ else
+ {
+ forward_list __tmp(__sz - __len);
+ splice_after(__k, std::move(__tmp));
+ }
+ }
+
template<typename _Tp, typename _Alloc>
void
forward_list<_Tp, _Alloc>::
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+
+// 2010-02-01 Paolo Carlini <paolo.carlini@oracle.com>
+
+// Copyright (C) 2010 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <forward_list>
+#include <testsuite_hooks.h>
+
+struct NoCopyConstructor
+{
+ NoCopyConstructor() : num(-1) { }
+ NoCopyConstructor(const NoCopyConstructor&) = delete;
+
+ operator int() { return num; }
+
+private:
+ int num;
+};
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::forward_list<NoCopyConstructor> fl(5);
+ VERIFY( std::distance(fl.begin(), fl.end()) == 5 );
+ for(auto it = fl.begin(); it != fl.end(); ++it)
+ VERIFY( *it == -1 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+
+// 2010-02-01 Paolo Carlini <paolo.carlini@oracle.com>
+
+// Copyright (C) 2010 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <forward_list>
+#include <testsuite_hooks.h>
+
+struct NoCopyConstructor
+{
+ NoCopyConstructor() : num(-1) { }
+ NoCopyConstructor(const NoCopyConstructor&) = delete;
+
+ operator int() { return num; }
+
+private:
+ int num;
+};
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::forward_list<NoCopyConstructor> fl;
+ VERIFY( std::distance(fl.begin(), fl.end()) == 0 );
+
+ fl.resize(10);
+ VERIFY( std::distance(fl.begin(), fl.end()) == 10 );
+ for(auto it = fl.begin(); it != fl.end(); ++it)
+ VERIFY( *it == -1 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
-// { dg-error "no matching" "" { target *-*-* } 1205 }
+// { dg-error "no matching" "" { target *-*-* } 1201 }
// { dg-excess-errors "" }
// Copyright (C) 2009, 2010 Free Software Foundation
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
-// { dg-error "no matching" "" { target *-*-* } 1205 }
+// { dg-error "no matching" "" { target *-*-* } 1201 }
// { dg-excess-errors "" }
// Copyright (C) 2009, 2010 Free Software Foundation
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
-// { dg-error "no matching" "" { target *-*-* } 1205 }
+// { dg-error "no matching" "" { target *-*-* } 1201 }
// { dg-excess-errors "" }
// Copyright (C) 2009, 2010 Free Software Foundation
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
-// { dg-error "no matching" "" { target *-*-* } 1205 }
+// { dg-error "no matching" "" { target *-*-* } 1201 }
// { dg-excess-errors "" }
// Copyright (C) 2009, 2010 Free Software Foundation