473,399 Members | 3,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Template specialization for vectors of any type

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
3 1718
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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Paul MG | last post by:
Hi Template partial specialization always seems like a fairly straightforward concept - until I try to do it :). I am trying to implement the input sequence type (from Stroustrup section...
6
by: Patrick Kowalzick | last post by:
Dear all, I have a question about default template parameters. I want to have a second template parameter which as a default parameter, but depends on the first one (see below). Is something...
2
by: SainTiss | last post by:
Hi, If you've got a template class with lots of methods, and then you've got a type which works with the template, except for one method... What you need to do there is specialize the...
17
by: Jacek Dziedzic | last post by:
Hello! I have a templated class that serves as a simple vector of elements. template <typename T> class simple_vector : public math_object { // ... lots of simple_vector operations // the...
31
by: nikola | last post by:
Hi all, I was working with a simple function template to find the min of two values. But since I would like the two values to be different (type) I dont know what kind of value (type) it will...
13
by: Imre | last post by:
Please take a look at the following code: template <typename T, typename Enable = void> class A { public: enum { value = 0 }; }; template <typename T>
3
by: Ruben Campos | last post by:
Greetings. Some time ago, I had writing a CVector <T, N> class, which implements an algebraic vector of arbitrary both dimension and scalar type. First, I defined the interface for the generic...
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
8
by: flopbucket | last post by:
Hi, I want to provide a specialization of a class for any type T that is a std::map. template<typename T> class Foo { // ... };
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.