Topic: Article: allocators...exceptions...new/delete [reply to: Sat, 12


Author: dhruvbird@gmx.net (Dhruv Matani)
Date: Wed, 16 Jul 2003 16:46:54 +0000 (UTC)
Raw View
On Sat, 12 Jul 2003 09:23:19 -0400, Andy Sawyer wrote:

> In article <pan.2003.07.10.18.19.19.500436@gmx.net>,
>  on 11 Jul 2003 08:49:35 -0400,
>  "Dhruv" <dhruvbird@gmx.net> wrote:
>
>> On Tue, 08 Jul 2003 02:32:22 +0000, Dhruv wrote:
>>
>> Just another quick question: Are allocators allowed to be templated
around
>> more that one template parameter?
>
> In the case of std::allocator, the answer is clearly no (due to the
> template template parameter issue).
> For other allocators, however, I see no reason why not - although
making
> rebind do the right thing might be interesting.
>

Thanks.


>> Also, with such a design, template template parameters would not
work, or
>> would they?
>
> It rather depends on what you mean...
>

I have replied to Richard Smith saying what I mean. Please have a look
at
it and tell me.

Regards,
-Dhruv.




---
[ 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                       ]





Author: dhruvbird@gmx.net (Dhruv Matani)
Date: Wed, 16 Jul 2003 17:53:52 +0000 (UTC)
Raw View
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:
>>
>> Just another quick question: Are allocators allowed to be templated
around
>> more that one template parameter?
>
> Absolutely.  There are requirements on the template parameters of the
> allocator.  There isn't even a requirement that it be templated,
though it's
> hard to think how else it could be implemented.  Basically, as long as
you
> can make rebind<> work, you're fine.
>

Ok, thanks.


>> Also, with such a design, template template parameters would not
work, or
>> would they?
>
> Not sure how you want to use template template parameters.
>
> If you want to do something like
>
>   template <class T, template <class> class Policy>
>   class my_allocator;
>
> this is fine.
>
> 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.


What I had in mind was something like this:

#include <memory>
#include <nstl/list_alloc.hpp>
#include <boost/pool/pool.hpp>

template <template <class type> class some_alloc >
struct foo {
  //type t;
  some_alloc<int> ia;
};

int main ()
{
  foo <nstd::list_node_allocator> f;
  foo <boost::fast_pool_allocator> f1;
}




That would eliminate the need to pass the type explicitly, and also, the
rebind hack would disappear in case of a list, or the map, etc......

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.


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


Regards,
-Dhruv.









---
[ 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                       ]