Template specialization for vectors of any type

M

mrstephengross

Ok, I've got a templated class Foo:

template<typename T> class Foo { ; };

I want to specialize Foo for vectors holding any type:

// Something like:
template<typename C> class Foo<std::vector<C> > { /* ... */ };

Is there any way to do this? Template template parameters, maybe?

Thanks!
--Steve ([email protected])
 
V

Victor Bazarov

mrstephengross said:
Ok, I've got a templated class Foo:

template<typename T> class Foo { ; };

What does the semicolon between the braces do?
I want to specialize Foo for vectors holding any type:

// Something like:
template<typename C> class Foo<std::vector<C> > { /* ... */ };

Is there any way to do this? Template template parameters, maybe?

But you just did it! Doesn't it work for you? See FAQ 5.8.

V
 
K

Kai-Uwe Bux

mrstephengross said:
Ok, I've got a templated class Foo:

template<typename T> class Foo { ; };

I want to specialize Foo for vectors holding any type:

// Something like:
template<typename C> class Foo<std::vector<C> > { /* ... */ };

Have you tried? Looks good to me. You may want to take care of the allocator
template parameter, too:

template < typename Val, typename Alloc >
class Foo said:
Is there any way to do this? Template template parameters, maybe?

No need for that.



Best

Kai-Uwe Bux
 
T

terminator

Kai-Uwe Bux said:
Have you tried? Looks good to me. You may want to take care of the allocator
template parameter, too:

template < typename Val, typename Alloc >


No need for that.



Best

Kai-Uwe Bux
the question looks to be like this:
//first define a template
template <class T> class tmplt {/*etc*/};
template <class C> class othertmplt;
//now specialize with templated parameter
template <class C> class tmplt < othertmplt<C> >{/*etc*/};

does such code compile? isn`t there any restrictions about
specialization?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top