Return Ordering Without a vector

前端 未结 1 552
心在旅途
心在旅途 2021-01-27 16:05

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

相关标签:
1条回答
  • 2021-01-27 16:36

    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

    0 讨论(0)
提交回复
热议问题