 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
James Kuyper Guest
|
Posted: Fri Jul 18, 2003 8:29 pm Post subject: Re: Article: allocators...exceptions...new/delete [reply to: |
|
|
[email]dhruvbird (AT) gmx (DOT) net[/email] (Dhruv Matani) wrote in message news:<1058347888.3149.18.camel (AT) home (DOT) free>...
| Quote: | On Sat, 12 Jul 2003 09:24:06 -0400, Richard Smith wrote:
"Dhruv" <dhruvbird (AT) gmx (DOT) net> wrote in message
news:pan.2003.07.10.18.19.19.500436 (AT) gmx (DOT) 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.
....
| Quote: | Now, it would be great if this would work:
#include <memory
#include
#include
template //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 f; //NOTE.
foo <boost::fast_pool_allocator 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.
| Quote: | 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 ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|