template<typename Container>void coolErase(Container &c, int count){ for (int i = 0; i < count; ++i) c.erase(i);}void MyClass1::DelRows( void ) { ... coolErase(node->data1, count); ...}
C++ (Qt) template <class R>R & get(Node * node); template<>data1_type & get<data1_type>(Node * node){ return node->data1;} template<>data2_type & get<data2_type>(Node * node){ return node->data2;} template <class T>class MyClass : public MyBase {... void MyClass::DelRows( void ){ ... for (int i = 0; i < count; ++i) { T & data = get(node); data.erase(i); } ...}
C++ (Qt) template <class R>R & get(Node * node); template<>data1_type & get<data1_type>(Node * node){ return node->data1;}
C++ (Qt)template <class T>struct MyTraits {}; template<>struct MyTraits<data1_type>{ static data1_type some_action() { ... } static other_type other_action() { ... } и т.д.. }; template <class T, class Traits = MyTraits<T>>class MyClass : public MyBase {...
C++ (Qt)template <class T>void MyClass::DelRows( void ){ ... for (int i = 0; i < count; ++i) { T & data = get(node); data.erase(i); } ...}
C++ (Qt)template <class T, class Traits = MyTraits<T>>class MyClass : public MyBase {}; typedef MyClacc<data1_type> MyClass1;typedef MyClacc<data2_type> MyClass2;
C++ (Qt)template <class T>void DoErase( const T *, Node * node, size_t index ) { static_assert(false, "Invalid T"); } template <>void DoErase( const MyClass1 *, Node * node, size_t index ) { node->data1.erase(index); } template <>void DoErase( const MyClass2 *, Node * node, size_t index ) { node->data2.erase(index); }