[haiku-commits] Re: haiku: hrev48723 - headers/os/support src/kits/network

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 26 Jan 2015 16:56:55 +0100

On 01/26/2015 04:40 PM, Adrien Destugues wrote:
On Mon, Jan 26, 2015 at 03:44:35PM +0100, Ingo Weinhold wrote:
On 01/26/2015 10:51 AM, pulkomandy@xxxxxxxxxxxxx wrote:
Add a BConstReference class.

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<const Type> would not work, as BReference needs to change
the reference count of the referenced object. Adding mutable and casting
where appropriate wouldwork but,

Why not provide a specialization for const types instead? It would save the
additional class and avoid the fairly ugly implementation.

I can't see what's the better way to do it, maybe I've been looking at
my own code for too long.

BReference<const Type> can't work because it cannot AcquireReference or
ReleaseReference (these mutate the referenced object), unless the const
is actually ignored by the BReference implementation (by casting it
away), or AcquireReference/ReleaseReference declared const, and the
fReferenceCount mutable, but I'm not sure this is a good way to handle
this.

Do you have another solution?

Well, as I wrote, a specialization for const types:

template<typename Type = BReferenceable>
class BReference {
public:
        // non-const implementation
        // ...
};

template<typename Type = BReferenceable>
class BReference<const Type> {
public:
        // const implementation
        // ...
};

I guess some duplication can be avoided by moving common stuff to a shared base class.

CU, Ingo


Other related posts: