Typedefing a partial template

Mar 9, 2009 at 4:42pm
In a similar vein as my previous question (all these little details of templates are a lot to wrap my head around -- this is the first time I've made a point to seriously use them).

I have a generic templated class from which I need to create a typename that 'fills in' some of the template parameters, but without needing to make a new class (so something like template specialization is not what I'm after). For example:

1
2
3
4
5
6
template <typename A, typename B>
class C { };

template <typename A>
typedef C<A,int>    D<A>;   // this apparently is illegal
                            //   but it illustrates what I want to do 


This way some template parameters can be hidden and don't need to be repeated:

1
2
D<char>     oneclass;  // <-- can do this... instead of 
C<char,int> twoclass;  // <-- this.  But they'd be the same type 


Since my above typedef idea doesn't work, the only other way I can see to do this would be an ugly #define:

 
#define D(A)  C<A,int> 


Is this avoidable?

EDIT -- I should also mention that default template parameters are not what I'm after, either.

Thanks!

another edit:

I thought about making a new class D which is a child of C, which sort of works except I have to repeat a bunch of ctors if I do that (which is less than ideal)
Last edited on Mar 9, 2009 at 4:47pm
Mar 9, 2009 at 10:48pm
Ah yes, the templated typedef.

Alas, this is not allowed under the current C++ standard.

Mar 9, 2009 at 11:20pm
Bummer.

Thanks.
Mar 9, 2009 at 11:40pm
More than once I could have used it. (That's why I know...)

Have you looked into templated templates? I don't know if they would help you. I'm not even familiar with how they work.

Mar 10, 2009 at 12:46am
They wouldn't work for me. The way I undestand them they're for using a class template inside of a template, rather than an instance of a class template inside of a template.

So like if I wanted to have 'vector' as a template argument instead of 'vector<int>', then I would use them. At least that's the example this ebook I have gives. I dont' see why that would be of any use though *shrug*.

Anyway I found a somewhat reasonable workaround. It's not as easy as this typedef would have been, but it'll be just as easy to use for the end-user of this lib I'm working on, so it's good enough.

Thanks again.
Topic archived. No new replies allowed.