Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return by reference and const overloads #49

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pr0g
Copy link

@pr0g pr0g commented Apr 1, 2023

This PR adds a const overload of GetPoint (that returns a const Point*) and updates GetTriangles and GetMap to return a const reference to the underlying data structure as opposed to returning by value (and forcing a copy).

A copy can still be made by not using a const ref variable.

e.g.

std::vector<p2t::Triangle*> triangles = cdt.GetTriangles(); // copy
const std::vector<p2t::Triangle*>& triangles = cdt.GetTriangles(); // no copy

I held off making any further changes to keep the PR small and simple. There are a few more spots that could benefit from const but it's not critical by any means.

Also to reduce duplication in the const/non-const overloads, I used the solution popularized by Scott Meyers in Effective C++ (Item 3) - see https://stackoverflow.com/a/123995/1947066 for details (I'm happy to change this to duplicate the logic in both overloads if you think that is clearer, or add a comment to explain what is being done and why).

Great library and I hope this incredibly minor contribution is helpful,

Thanks!

Signed-off-by: Tom Hulton-Harrop <tom.hultonharrop@gmail.com>
Signed-off-by: Tom Hulton-Harrop <tom.hultonharrop@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant