templated typedef;

I have a 1st order RC low-pass filter. It's implemented as a class called [/code]Filt[/code], and is defined as:
1
2
template <class T> 
class Filt {/*...*/};
That name was chosen because the colloquial phrase "I need to filter this" tends to refer to an RC low-pass filter.

Now if someone is looking for a low-pass filter in my library, they will only find Filt which they may not recognize as a low-pass filter, so I want to typedef this to simply give it another alias.

Unfortunately the template is getting in my way:

1
2
3
4
5
6
7
8
9
10
typedef Filt LowPass;

typedef Filt<> LowPass;

typedef Filt<> LowPass<>;

template <typename T>
typedef Filt<T> LowPass;

typedef Filt<double> LowPass;
error C2955: 'sim::Filt' : use of class template requires template argument list

error C2976: 'sim::Filt' : too few template arguments

error C2143: syntax error : missing ';' before '<'

error C2823: a typedef template is illegal


OK


Is there a way to do this? I suppose inheritance would work instead but that requires extra code for the constructor and operator functions.
If I get what you are trying to do - then you will find trying to typedef
a generic template is problematic/impossible.

So in C++11 you can use the using declaration like this:
1
2
template <typename T>
using MyFilter = Filt<T>; //now MyFilter is a typedef for  Filt 


You can also use using in this manner where previously you would
have used the keyword typedef.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
template <class T>
class Filt {/*...*/};

/*typedef Filt LowPass;

typedef Filt<> LowPass;

typedef Filt<> LowPass<>;

template <typename T>
typedef Filt<T> LowPass;

typedef Filt<double> LowPass;*/


template <typename T>
using MyFilter = Filt<T>;

using MyFilter_Int = MyFilter<int>;


int main()
{

    MyFilter_Int mfi;

}
Last edited on
Thanks guys.
Topic archived. No new replies allowed.