I'm doing some pre-code planning,
I am curious if/how possible the following templates would be? For my example, Class A contains a vector of Class B, which contains a vector of Class C, which contains a vector of Class D. It's quite modular.
Template 1 - trim()
I would like to write a template that can take in a vector, and automatically trim it's capacity down to it's size. I have to do this in two places, with different types of vectors, vector<C> and vector<D>. The code for trim() is really simple:
- vector<object_type>(v).swap(v);
Also, this is a simplified version of Template 2, which I am more interested in using.
Template 2 - cascade()
My plan has a lot of symmetry, it's like class A is the top tier, and then I want the calls to propagate down into the lower tiers. For example in the constructor A() I call constructor B() which calls constructor C() which calls constructor D(). As a result, I have many functions which are pseudocoded:
- // properly declare it as the iterator for vector PARAM1
-
for(it = PARAM1.begin; it != PARAM1.end; it++)
-
it->PARAM2();
I am assuming if we pass a pointer to the vector, it will remember the object type, and size, unlike an array.
Is there anything else I should know?