C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: Article: allocators...exceptions...new/delete [reply to:

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Richard Smith
Guest





PostPosted: Thu Jul 17, 2003 3:17 pm    Post subject: Re: Article: allocators...exceptions...new/delete [reply to: Reply with quote




"Dhruv Matani" <dhruvbird (AT) gmx (DOT) net> wrote

Quote:
What I had in mind was something like this:

#include <memory
#include

I assume this is the one from
http://www.geocities.com/dhruvbird/nstl0.2.zip. For the benefit of anyone
else reading this thread, list_node_allocator is a stateless allocator
declared as follows.

namespace nstd {
template class list_node_allocator;
}

Quote:
#include <boost/pool/pool.hpp

Let me quote the declaration of fast_pool_allocator:

namespace boost {
template class UserAllocator = /* default value */,
class Mutex = /* default value */,
unsigned NextSize = 32>
class fast_pool_allocator;
}

Note in particular the extra template parameters.

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

The template argument to foo must be a class template with one template
parameter.

Quote:
int main ()
{
foo <nstd::list_node_allocator> f;

This is fine: list_node_allocator is a class template with one template
parameter.

Quote:
foo <boost::fast_pool_allocator> f1;

This is not legal: fast_pool_allocator is a class template with four
template parameters. The fact that the last three have default values is
irrelevant. There is a core language defect report (DR150) about this. See

http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_closed.html#150

for more details. Some compilers do accept this code, but you must bear in
mind that it is not strictly legal. Unless this is resolved (and I hope it
will be in C++0x), this is one reason why allocators don't work too well as
template template parameters.

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

I agree, this would have been nice, but I think it's too late now.

Quote:
Now, it would be great if this would work:

#include <memory
#include #include
template