S
stephen.diverdi
Can anyone lend a hand on getting this particular template
specialization working? I've been trying to compile with g++ 4.1 and
VS 2005.
//------------------------------------------------------------------
// my regular glass
class A { };
// my templated class
template < typename T > class B { };
// this is a library class with a library function i want to
specialize for my classes
template < typename T >
class C
{
public:
void func ( T arg )
{
fprintf( stderr, "C< T >\n" );
}
};
// specialization on A works just fine
template < >
void C< A >::func ( A arg )
{
fprintf( stderr, "C< A >\n" );
};
// specialization on B<T> fails to compile
template < typename T >
void C< B< T > >::func ( B< T > arg )
{
fprintf( stderr, "C< B< T > >\n" );
};
//------------------------------------------------------------------
The motivation for this is I have a templated class that has
particular memory allocation requirements (I need it to be aligned),
that I'd like to be able to use with STL containers without having to
pass in a custom allocator every time. So I'm trying to overload
std::allocator's allocate and deallocate member functions to work on
my template class. I'm afraid this is a funny form of partial
specialization of a function and I'm just out of luck, but maybe
there's a workaround? I'm sure other people have had similar
difficulties...Thanks,
-stephen diverdi
(e-mail address removed)
specialization working? I've been trying to compile with g++ 4.1 and
VS 2005.
//------------------------------------------------------------------
// my regular glass
class A { };
// my templated class
template < typename T > class B { };
// this is a library class with a library function i want to
specialize for my classes
template < typename T >
class C
{
public:
void func ( T arg )
{
fprintf( stderr, "C< T >\n" );
}
};
// specialization on A works just fine
template < >
void C< A >::func ( A arg )
{
fprintf( stderr, "C< A >\n" );
};
// specialization on B<T> fails to compile
template < typename T >
void C< B< T > >::func ( B< T > arg )
{
fprintf( stderr, "C< B< T > >\n" );
};
//------------------------------------------------------------------
The motivation for this is I have a templated class that has
particular memory allocation requirements (I need it to be aligned),
that I'd like to be able to use with STL containers without having to
pass in a custom allocator every time. So I'm trying to overload
std::allocator's allocate and deallocate member functions to work on
my template class. I'm afraid this is a funny form of partial
specialization of a function and I'm just out of luck, but maybe
there's a workaround? I'm sure other people have had similar
difficulties...Thanks,
-stephen diverdi
(e-mail address removed)