multiscale / muscle3

The third major version of the MUltiScale Coupling Library and Environment
Apache License 2.0
25 stars 13 forks source link

Use Data instead of DataConstRef internally #288

Open LourensVeen opened 5 months ago

LourensVeen commented 5 months ago

DataConstRef is rather tricky because of its weird Python-style sometimes-value-sometimes-reference semantics, which don't integrate well with the concept of constness. This is causing trouble when we use it internally, and we're probably better off just using Data everywhere internally so we don't need weird hacks in mocks and tests. All this of course while we await that magical time when we figure out how to cleanly integrate sometimes-value-sometimes-reference semantics with constness and make it all perfect.

LourensVeen commented 5 months ago

Actually, it seems like a DataConstPtr would be better. This would be derived from DataConstRef, and add copy-assignment and move-assignment operators. That would make it compatible with standard containers, and would still keep the referred-to data from being modified. We could also safely add conversions from DataConstRef to DataConstPtr and back (back is automatic if DCP derives from DCR).

The only place where DataConstPtr wouldn't be able to replace DataConstRef is as the return value of DCR::operator[] or DCP::operator[], because that would break constness. So that will remain DataConstRef.