Topic: Article: allocators...exceptions...new/delete [reply to: Sat, 12 Jul 2003 09:24:06 -0400, Richard Smith].


Author: kuyper@wizard.net (James Kuyper)
Date: Fri, 18 Jul 2003 20:29:16 +0000 (UTC)
Raw View
dhruvbird@gmx.net (Dhruv Matani) wrote in message news:<1058347888.3149.18.camel@home.free>...
> On Sat, 12 Jul 2003 09:24:06 -0400, Richard Smith wrote:
>
> > "Dhruv" <dhruvbird@gmx.net> wrote in message
> > news:pan.2003.07.10.18.19.19.500436@gmx.net...
> >> On Tue, 08 Jul 2003 02:32:22 +0000, Dhruv wrote:
...
> > If you want to do
> >
> >   template <class T> class my_allocator;
> >   std::vector< int, my_allocator > v;
> >
> > it is not OK.
>
> I haven't quite understood what you're trying to say here, and why won't
> the 2nd eg. work.

The second template argument to any of the standard container classes
is a type, not a template name. my_allocator is a template.
my_allocator<T> for a given value of T, is a type.

...
> Now, it would be great if this would work:
>
> #include <memory>
> #include <nstl/list_alloc.hpp>
> #include <boost/pool/pool.hpp>
>
> template <template <class type> class some_alloc<type> > //NOTE.
> struct foo {
>   //type t;
>   some_alloc<type> ia;
> //now, if you want a node allocator, just do:
> //some_alloc<node_struct> na;
> };
>
> int main ()
> {
>   foo <nstd::list_node_allocator<int> > f; //NOTE.
>   foo <boost::fast_pool_allocator<int> > f1; //NOTE.
> }
>
>
> I'm not too sure about whether the code is even correct. Please tell me
> if
> it's correct, because I don't trust g++ much on template issues.

No, it's not. You've declared that the first template argument of
foo<> is a template name; you're not allowed to provide a type
argument instead.

> Something that I'm quite sure about is that the boost allocator example
> (f1 object thing) does not compile because of the the n number of
> parameters that it has.
>
> One more thing: Is it legal to access 'type' within the struct, as in,
> can you do something like this inside the struct:
>
> some_alloc<type> alloc;
>
> It doesn't seem to work on g++.

No, the 'type' is just a dummy parameter; what you're trying is
exactly analogous to the following:

void g(int (*f)(int i))
{
    f(i);
}

Where g corresponds to foo, f corresponds to some_alloc, and i
corresponds to 'type'. The reason why you can't access 'i' is exactly
analogous to the reason you can't use 'type'.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]