Boost logo

Boost :

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


"Alberto Barbati" <abarbati_at_[hidden]> wrote in message
news:c1baon$fhb$1_at_sea.gmane.org...
> Hi Boosters,

> 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.

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.

Jonathan


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