By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,413 Members | 996 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,413 IT Pros & Developers. It's quick & easy.

Template specialization for vectors of any type

P: n/a
Ok, I've got a templated class Foo:

template<typename Tclass Foo { ; };

I want to specialize Foo for vectors holding any type:

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

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

Thanks!
--Steve (mr************@hotmail.com)

Nov 7 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
mrstephengross wrote:
Ok, I've got a templated class Foo:

template<typename Tclass Foo { ; };
What does the semicolon between the braces do?
I want to specialize Foo for vectors holding any type:

// Something like:
template<typename Cclass 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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 7 '06 #2

P: n/a
mrstephengross wrote:
Ok, I've got a templated class Foo:

template<typename Tclass Foo { ; };

I want to specialize Foo for vectors holding any type:

// Something like:
template<typename Cclass 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< std::vector<Val,Alloc { /* ... */ };
Is there any way to do this? Template template parameters, maybe?
No need for that.

Best

Kai-Uwe Bux
Nov 7 '06 #3

P: n/a

Kai-Uwe Bux wrote:
mrstephengross wrote:
Ok, I've got a templated class Foo:

template<typename Tclass Foo { ; };

I want to specialize Foo for vectors holding any type:

// Something like:
template<typename Cclass 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< std::vector<Val,Alloc { /* ... */ };
Is there any way to do this? Template template parameters, maybe?

No need for that.

Best

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

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

Nov 7 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.