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)
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.