Add a BConstReference class

Operating Systems / Haiku - Adrien Destugues [gmail.com] - 26 January 2015 03:50 UTC

This is a BReference that allows only const access to the referenced object. This was not easily possible with the existing BReference for two reasons:
- BReference would not work, as BReference needs to change the reference count of the referenced object. Adding mutable and casting where appropriate wouldwork but,
- It is now also possible to assign a BReference to a BConstReference (to the same type, of course). The reverse is not allowed, making it more difficult to "const cast" the referenced object (it's still possible to "get" the object pointer and cast that).

BConstReference can be used to provide shared read-only access to an object, for example this can be used to cache non-copiable or expansive to create objects.

e9b8242 Add a BConstReference class.
headers/os/support/Referenceable.h | 59 ++++++++++++++++++++++++++++--------
1 file changed, 47 insertions(+), 12 deletions(-)

Upstream: cgit.haiku-os.org


  • Share