Commit ec489971 authored by Martin Heistermann's avatar Martin Heistermann

Fix lifetime issues for Face::halfedges(), Cell::halffaces().

Currently, the following API-usage is straight-forward and clean but
unfortunately wrong and dangerous:

`for (const auto heh: mesh.face(fh).halfedges()) { ... }`

This is because the temporary `Face` returned by `face()` reaches the
end of its lifetime, but `halfedges()` returned a reference to a vector that
lives inside that object. Reference lifetime extension does not apply
here.

This change splits behaviour so that in rvalue context (such as
temporaries), we move out the vector instead of returning a reference to
it.
parent 2354de4c
Pipeline #8630 passed with stage
in 5 minutes and 49 seconds
......@@ -97,10 +97,15 @@ public:
virtual ~OpenVolumeMeshFace() {
}
const std::vector<HalfEdgeHandle>& halfedges() const {
const std::vector<HalfEdgeHandle>& halfedges() const & {
return halfedges_;
}
const std::vector<HalfEdgeHandle>& halfedges() const && = delete;
std::vector<HalfEdgeHandle> halfedges() && {
return std::move(halfedges_);
}
protected:
void set_halfedges(const std::vector<HalfEdgeHandle>& _halfedges) {
......@@ -126,10 +131,15 @@ public:
virtual ~OpenVolumeMeshCell() {
}
const std::vector<HalfFaceHandle>& halffaces() const {
const std::vector<HalfFaceHandle>& halffaces() const & {
return halffaces_;
}
const std::vector<HalfFaceHandle>& halffaces() const && = delete;
std::vector<HalfFaceHandle> halffaces() && {
return std::move(halffaces_);
}
protected:
void set_halffaces(const std::vector<HalfFaceHandle>& _halffaces) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment