c++ - Reducing template bloat with inheritance -
Is anyone experiencing reducing the template code bloat using inheritance?
I would hesitate to rewrite our containers in this way:
square vectorbase {public: integer size (); Zero clear (); Int m_size; Zero * m_rawData; // ....}; The template's & lt; Tinnamam T & GT; Square vector: public vectorbase {zero pus_back (constant t & amp;); // ...};
I should have maximum exposure while reducing compilation time
I also wonder why SLL implementation does not use this approach
Feedback
Only a few operations are understood on the vector, if you do not know how Have the stored elements of For example clear ()
method that you add to your base class, you need to call the recipients of the elements removed from the vector, so they need to know their type and They should be templed.
There really is not much, you can not even know about a few things inside a zero * m_rawdata , basically all of that on it The types of tasks to know at least the size of the collection will be. The only thing I can think about is that you can do
free
if you know that there is no element in it (if it contains elements that you call your destructors). Allotting, setting and accessing elements is not all work if you do not know where individual elements start and end, except that the implementation of all methods will be very clean and simple if instead of m_rawData
is typed correctly T *
.
A size ()
The method will only work in the base class if its only job is to return a m_size
member variable, but a vector is clear The shape is not to be stored in size (implementation is not known). Perhaps you can apply so that the size is clearly stored, but then size ()
is probably not a method that takes a long time to compile, even if it is templated Ho.
Together, I do not think there are so many ways left, which are implemented in a base class. At the vector, most operations need to know about the elements stored in it.
Comments
Post a Comment