So I am calling a helper function, vertex_triangle
, quite a bit to allow me to take in a vector
and wind them into ordered tria
So your comment on using an out parameter is the most direct option here. The other alternative would be to return a lambda, which would capture your inputs by reference. So for example:
template <typename T>
auto vertex_triangle(const size_t index, const vector<pair<T, T>>& polygon) {
const auto& first = index == 0U ? polygon.back() : polygon[index - 1U];
const auto& second = polygon[index];
const auto& third = index == size(polygon) - 1U ? polygon.front() : polygon[index + 1U];
return [&](auto& output){ output.push_back(first);
output.push_back(second);
output.push_back(third); };
}
Could be called like this:
vertex_triangle(i, bar)(foo)
Live Example