Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-02-23 20:48:15

"Alberto Barbati" <abarbati_at_[hidden]> wrote in message
> Hi Boosters,

> What about having a similar template for allocators? Given that a
> class of useful allocators are de facto built over a couple of
> malloc-like/free-like functions, I imagine something that could be
> 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
> that std::allocator<T> does.

I think it's worthwhile providing a library template whenever the task
of producing a type satisfying standard library requirement can be
reduced to satisfying some simpler interface. codecvt's might be
another candidate. Personally I don't think I'd use it much, because I
rarely write allocators.

How general can you make it? What percentage of custom allocators
could be defined this way?

I'd suggest giving the policy a value_type and making allocator_facade
a unary template; if a class of policies are the same except for
value_type you can always write a templated policy.


Boost list run by bdawes at, gregod at, cpdaniel at, john at