c++ - How can one avoid duplicating class template specification for each member function? -
if have template class specification so,
template <typename t> class myclass { public: void fun1(); // ... void funn(); }; template <typename t> void myclass<t>::fun1() { // definition } // ... template <typename t> void myclass<t>::funn() { // definition }
if change class template else, add parameter:
template <typename t, typename u> class myclass { // ... };
then have change each function definition (fun1, ..., funn) agree class template specification:
template <typename t, typename u> void myclass<t,u>::fun1() { //... }
are there strategies avoiding this? use macros e.g.
#define dflt_template template<typename t, typename u> #define dflt_class class<t,u> dflt_template void dflt_class::fun1() { // ... }
or considered bad practice?
to me, benefits of using macro here far overshadowed drawbacks. yes, if use macro if ever need add additional template parameter, you'll need make single modification. else reading code going vomit.
i mean, going every template have? code become infested ugly macros.
Comments
Post a Comment