Return Ordering Without a vector

穿精又带淫゛_ 提交于 2019-12-02 09:02:56

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!