molpopgen / fwdpp

fwdpp is a C++ template library for implementing efficient forward-time population genetic simulations
http://fwdpp.readthedocs.io
GNU General Public License v3.0
27 stars 11 forks source link

Ownership semantics for the marginal trees. #292

Open molpopgen opened 3 years ago

molpopgen commented 3 years ago

We currently store an object and return a const reference via a getter. This design is rather inelegant. We should refactor to use shared pointers. The getter returns a pointer to const object to prevent modification by the caller.

molpopgen commented 3 years ago

Getting this right is a bit annoying. On the caller's side, one must use auto && to properly receive the shared_ptr as const.

molpopgen commented 3 years ago

This should be handled along with #294, at which point we should deprecate the existing types that do the const & method.

molpopgen commented 3 years ago

Random thought: this may all be best handled by a get method returning const *?

molpopgen commented 3 years ago

Random thought: this may all be best handled by a get method returning const *?

No -- you can always delete a pointer. Seems like the smartest thing here is the shared/weak pointer duo.