This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

... and a *draft* patch!



2- Change the __uninitialized_*, or, in other terms, add a three
    arguments _Construct overload for use there.

Everything considered I prefer 2-, for this reason: when the resolution
of 438 will be in effect, it will suffice to simply remove all the
_Construct (both two and three arguments) and call __alloc::construct
directly from the __uninitialized_*. In the meanwhile we would end
up with a consistent set of _Construct / _Destroy and a consistent set
of uses from the __uninitialized; all the changes concentrated in
stl_uninitialized and stl_construct.

... of course missing comments, testcases, etc., etc., only to concretely explain my take.

Paolo.

P.S. The failure of vector/capacity/2.cc for a preliminary version, pointed
out that we can often spare unnecessary copy-constructions.

////////////////
diff -urN libstdc++-v3-orig/include/bits/stl_construct.h libstdc++-v3/include/bits/stl_construct.h
--- libstdc++-v3-orig/include/bits/stl_construct.h	2004-07-28 18:37:17.000000000 +0200
+++ libstdc++-v3/include/bits/stl_construct.h	2004-10-17 02:43:07.000000000 +0200
@@ -62,7 +62,9 @@
 #define _STL_CONSTRUCT_H 1
 
 #include <bits/type_traits.h>
+#include <bits/cpp_type_traits.h>
 #include <new>
+#include <bits/stl_iterator_base_types.h>
 
 namespace std
 {
@@ -81,6 +83,42 @@
       ::new(static_cast<void*>(__p)) _T1(__value);
     }
 
+  template<bool _BoolType>
+    struct _Construct_aux
+    {
+      template<typename _ForwardIterator, typename _T2, typename _Allocator>
+        static void
+        Construct(_ForwardIterator __first, const _T2& __value,
+		  _Allocator __alloc)
+        {
+	  __alloc.construct(&*__first, __value);
+	}
+    };
+
+  template<>
+    struct _Construct_aux<false>  
+    {
+      template<typename _ForwardIterator, typename _T2, typename _Allocator>
+        static void
+        Construct(_ForwardIterator __first, const _T2& __value,
+		  _Allocator __alloc)
+        {
+	  __alloc.construct(&*__first, typename
+			    iterator_traits<_ForwardIterator>::
+			    value_type(__value));
+	}
+    };
+
+  template<typename _ForwardIterator, typename _T2, typename _Allocator>
+    inline void
+    _Construct(_ForwardIterator __first, const _T2& __value,
+	       _Allocator __alloc)
+    {
+      typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
+      const bool __same = __are_same<value_type, _T2>::_M_type;
+      _Construct_aux<__same>::Construct(__first, __value, __alloc);
+    }
+
   /**
    * @if maint
    * Constructs an object in existing memory by invoking an allocated
diff -urN libstdc++-v3-orig/include/bits/stl_uninitialized.h libstdc++-v3/include/bits/stl_uninitialized.h
--- libstdc++-v3-orig/include/bits/stl_uninitialized.h	2004-07-28 18:37:17.000000000 +0200
+++ libstdc++-v3/include/bits/stl_uninitialized.h	2004-10-17 00:48:38.000000000 +0200
@@ -235,7 +235,7 @@
       try
 	{
 	  for (; __first != __last; ++__first, ++__cur)
-	    __alloc.construct(&*__cur, *__first);
+	    std::_Construct(__cur, *__first, __alloc);
 	  return __cur;
 	}
       catch(...)
@@ -263,7 +263,7 @@
       try
 	{
 	  for (; __cur != __last; ++__cur)
-	    __alloc.construct(&*__cur, __x);
+	    std::_Construct(__cur, __x, __alloc);
 	}
       catch(...)
 	{
@@ -291,7 +291,7 @@
       try
 	{
 	  for (; __n > 0; --__n, ++__cur)
-	    __alloc.construct(&*__cur, __x);
+	    std::_Construct(__cur, __x, __alloc);
 	}
       catch(...)
 	{

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]