]> gcc.gnu.org Git - gcc.git/commitdiff
forward_list.h (forward_list<>::resize(size_type), [...]): Only declare.
authorPaolo Carlini <paolo.carlini@oracle.com>
Mon, 1 Feb 2010 13:10:12 +0000 (13:10 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Mon, 1 Feb 2010 13:10:12 +0000 (13:10 +0000)
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.

From-SVN: r156426

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/forward_list.h
libstdc++-v3/include/bits/forward_list.tcc
libstdc++-v3/testsuite/23_containers/forward_list/cons/10.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/forward_list/modifiers/6.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/assign_neg.cc
libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor_1_neg.cc
libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/constructor_2_neg.cc
libstdc++-v3/testsuite/23_containers/forward_list/requirements/dr438/insert_neg.cc

index e9dc874e1264985cc973e3560faac4b22168a27b..a3e0a4249639335b9bb02196cd797894150323ce 100644 (file)
@@ -1,3 +1,22 @@
+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/
index b90c8cf6d6682b4d80135026a4df30c46f2f72f9..d7005e828c5959950aa4df5585b593c6c373b32b 100644 (file)
@@ -442,17 +442,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       { }
 
       /**
-       *  @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.
@@ -497,7 +494,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *  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()); }
 
       /**
@@ -870,7 +867,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       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));
@@ -895,7 +892,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
         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));
@@ -918,7 +915,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       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));
@@ -993,12 +990,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *  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
index 1575cabf1f2145df3ee7f37ac305f083dafe4c4b..685e533c385550a2e261bf0e262e90606687a82d 100644 (file)
@@ -1,6 +1,6 @@
 // <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
@@ -174,6 +174,19 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
         }
     }
 
+  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>::
@@ -201,6 +214,28 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       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>::
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/cons/10.cc b/libstdc++-v3/testsuite/23_containers/forward_list/cons/10.cc
new file mode 100644 (file)
index 0000000..4e599da
--- /dev/null
@@ -0,0 +1,50 @@
+// { 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;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/6.cc b/libstdc++-v3/testsuite/23_containers/forward_list/modifiers/6.cc
new file mode 100644 (file)
index 0000000..985f592
--- /dev/null
@@ -0,0 +1,53 @@
+// { 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;
+}
index 7e6e6492a2ca8f9cd83e00ac3e7d48bc8abc5a07..5351a5b07884987739aa82dcc26a2463ed7df93c 100644 (file)
@@ -1,6 +1,6 @@
 // { 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
index 439a7b3219189c2a26286da6b612937cc6b1751c..b624ab2356f0b03fd3b66c2a2d599a3d25a3ef7b 100644 (file)
@@ -1,6 +1,6 @@
 // { 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
index 8184b67d750f723b92fe57474d3877ea4fa2e872..0a593c83a91b992c019a6399613816ffd7f1f64c 100644 (file)
@@ -1,6 +1,6 @@
 // { 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
index 0bc1a3d58cb1e8129df8e3ba3d541b70e39d48a9..4739ce77f753da7a7088e8bc5b7953853f10fee7 100644 (file)
@@ -1,6 +1,6 @@
 // { 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
This page took 0.07702 seconds and 5 git commands to generate.