How to declare/define a class with template template parameters without using an extra template parameter?

I assume you're after X, as well as A, in your code The usual pattern is to have template struct B { C c; } and then, inside classes eligible for substitution: template class A { typedef X type_name; X t; } Then you can access the template parameter using C::type_name.

I assume you're after X, as well as A, in your code. The usual pattern is to have template struct B { C c; }; and then, inside classes eligible for substitution: template class A { typedef X type_name; X t; }; Then you can access the template parameter using C::type_name.

Thanks for the answer though I eventually discovered this myself. I was in the process of editing the question and posting my work around but apparently I had come to the right place to ask this question! – SDX2000 Nov 24 '08 at 14:05 note that Sunlight's answer is better than mine, since he has understood what you want.No need to rebind like I showed you.

That would only be required if you use A, but occasionally have the need or A. Or if the user's view is A, but you use A . – Johannes Schaub - litb Nov 24 '08 at 14:14 +1!

I was searching for a way to receive a reference to any standard container, and using this way getting the type with C::value_type was really useful. Thanks! – Vargas Nov 10 '10 at 17:19.

This is not possible. Note that this is a common misunderstanding: A is not a class template anymore! So it would not fit to a template-template parameter, but would have to be accepted using a type-parameter: template struct B { C c; }; B b; Your way of using a separate parameter is alright.

If you want to accept A but want to re-bind it to another parameter, you can use this pattern, also used by standard-allocators: template struct A { template struct rebind { typedef A type; }; }; template struct B { typename C::template rebind::type c; }; B b; Now, B::c is of type A. The typename before C:: tells the compiler the ::type at the end is a type and not a static non-type member. The template after C:: tells the compiler the rebind is a template instantiation, and not a comparision.

Ok cool! Nice answer but unfortunately there can only be one answer and I think @sunlight posted his solution earlier to you. I have upvoted your answer.

– SDX2000 Nov 24 '08 at 14:14.

What is wrong with: template struct B { C c; }; int main() { B > b; return 0; }.

My bad, the problem was not fully specified. Now it is. – SDX2000 Nov 24 '08 at 14:06.

You can nest parameters. That is, the value of a parameter can itself be parameterized. Template struct A { X t; }; template struct B { C c; }; int main() { B > b; return 0; } In this example, the declaration of be in main() creates a specialization of A using int as the parameter, then it creates a specialization of B using A as the parameter.

Thus, in the specialization of B, C is A.

Your solution is correct according to the original question but I have added some details I missed the first time. Thanks. – SDX2000 Nov 24 '08 at 14:26.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions