Boost logo

Boost :

From: Alberto Barbati (abarbati_at_[hidden])
Date: 2004-02-22 17:34:30


Hi Boosters,

I had a very good time writing iterators with the new iterator_facade
template. Very good job! It makes writing iterators so much simpler!

What about having a similar template for allocators? Given that a large
class of useful allocators are de facto built over a couple of typeless
malloc-like/free-like functions, I imagine something that could be used
like this:

   struct malloc_impl
   {
     static void* allocate(size_t n) { return malloc(n); }
     static void deallocate(void* p) { free(p); }
   };

   std::vector<int, boost::allocator_facade<int, malloc_impl> > v;

where boost::allocator_facade<T, malloc_impl> satisfies all requirements
that std::allocator<T> does.

An implementation for a conforming compiler and library is
straightforward and allocator_facade could also include workarounds for
specific platforms where possible (for example it can easily and
automatically provide the __stl_alloc_rebind hack in STLport).

Is there any interest for such a thing?

Alberto


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk