a very simplistic (and silly) abstraction of what I’m doing is described below:
class A{
private:
template <typename InIt>
A foo(InIt begin, InIt end, A& a) {
// {begin, ind} is a datastructure containing all "terms" to search for.
auto iter(sub.begin());
auto e(sub.end());
// search trough all elements in original structure.
do
if (FUNC) {
if (++begin != end) {
return iter->foo(begin, end, a.append_values(iter));
//append_values appends a copy of the element's values at iter
//does not copy the sub "trees" of the element at "iter"
//it returns a reference to the appended sub "tree"
} else {
return a;
}
}
} while (++iter != e);
return a;
}
};
Sub is a vector containing objects of class “A” – so effectivelly creating a tree-datastructure. FUNC is a function that must be true for the branch to be “added” to the new tree.
What I’m wondering is: how many copys are “created” if, say, the depth (difference between initial begin, end) is “X”. – I’m fearing that for each depth a new copy of “a” is created. This is something I wish to prevent. So should I return by reference? – Or by pointer?
UncleBens indeed gave the correct question I needed to find a “solution”.
I completely “forgot” you can obviously use arguments-by-reference as output too. I don’t have to return anything as I edit the original “a”, not a copy.