c++ - Creating an alias for an instantiated template -
i had number of signal processing filter classes identical apart few constants defining filter characteristic, decided change these template class maintainability , extensibility. there performance , memory management reasons preferring template on constructor arguments in case; embedded system.
consequently have template class of form:
template <int size, int scale_multiplier, int scale_shift> class cboxcarfilter { public: // allow access size @ runtime. static const int filter_size = size ; ... }
which explicitly instantiate thus, example:
template class cboxcarfilter<8, 1, 3>
the problem when need access filter_size member requires:
cboxcarfilter<8, 1, 3>::filter_size
which rather makes access filter_size redundant since must repeated in arguments. solution problem this:
// create alias filter #define cspecialistboxcarfilter cboxcarfilter<8, 1, 3> template class cspecialistboxcarfilter ;
then can access filter_size thus:
cspecialistboxcarfilter::filter_size
this has advantage of meaningful unique names each filter instance in original non-templated versions, seems smelly me using macro looks class since has different scope semantics.
is there better way of creating alias class names template instance?
yes, typedef
!
typedef cboxcarfilter<8, 1, 3> cspecialistboxcarfilter;
Comments
Post a Comment