This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

Re: small oversight in new_allocator.h


On Fri, 2004-01-30 at 13:40, Dhruv Matani wrote:
> On line 80: of new_allocator.h, a reference is made to
> allocator<void>::....... whereas allocator is not included in that file.
> Suggested change: replace by const void* (which makes me wonder whether
> it makes sense to have void objects?)

Here's the patch. Added the specialization for new_allocator<void> and
added the comparison functions.


-- 
	-Dhruv Matani.
http://www.geocities.com/dhruvbird/


*** new_alloc.old	Fri Jan 30 19:18:43 2004
--- new_alloc.new	Fri Jan 30 19:17:09 2004
*************** namespace __gnu_cxx
*** 43,48 ****
--- 43,60 ----
     *
     *  (See @link Allocators allocators info @endlink for more.)
     */
+   template <typename _Tp> class new_allocator;
+ 
+   // specialize for void:
+   template <> class new_allocator<void> {
+   public:
+   typedef void*       pointer;
+     typedef const void* const_pointer;
+     //  reference-to-void members are impossible.
+     typedef void  value_type;
+     template <typename _Tp1> struct rebind { typedef new_allocator<_Tp1> other; };
+   };
+   
    template<typename _Tp>
      class new_allocator
      {
*************** namespace __gnu_cxx
*** 77,83 ****
        // NB: __n is permitted to be 0.  The C++ standard says nothing
        // about what the return value is when __n == 0.
        pointer
!       allocate(size_type __n, allocator<void>::const_pointer __h = 0)
        { return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp))); }
  
        // __p is not permitted to be a null pointer.
--- 89,95 ----
        // NB: __n is permitted to be 0.  The C++ standard says nothing
        // about what the return value is when __n == 0.
        pointer
!       allocate(size_type __n, new_allocator<void>::const_pointer __h = 0)
        { return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp))); }
  
        // __p is not permitted to be a null pointer.
*************** namespace __gnu_cxx
*** 98,103 ****
--- 110,130 ----
        void 
        destroy(pointer __p) { __p->~_Tp(); }
      };
+ 
+   //Comparison functions. Since this Allocator (new_allocator) is
+   //stateless, we always assume that 2 instances are alawys equal.
+   template <typename _Tp1, typename _Tp2>
+   bool operator== (const new_allocator<_Tp1>&, const new_allocator<_Tp2>&) throw()
+   {
+     return true;
+   }
+ 
+   template <typename _Tp1, typename _Tp2>
+   bool operator!= (const new_allocator<_Tp1>&, const new_allocator<_Tp2>&) throw()
+   {
+     return false;
+   }
+ 
  } // namespace __gnu_cxx
  
  #endif

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