Make member<T> not heap-allocated with ZCPOINTER_TRACK_REFS.
authorRobert Sesek <rsesek@bluestatic.org>
Wed, 12 Oct 2016 01:23:08 +0000 (21:23 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Wed, 12 Oct 2016 01:23:08 +0000 (21:23 -0400)
commit41210b092c1acc83ee33d7becc24298e2fbe4bfb
tree76f813e258d413c94c78250eed0be48c3a8c54b6
parentb05b787894c21df3a94584e2a048ce0fe9008050
Make member<T> not heap-allocated with ZCPOINTER_TRACK_REFS.

Instead, member<T> is a subclass of T with |operator&| overloaded. And a new
OwnershipBehavior field is added to the OwnedPtrDeleter, to control whether
delete should be invoked on the pointer. For member<T>, the behavior is to not,
while for owned<T> the behavior is to delete.

The new field does increase codesize for member<T> when using TRACK_REFS, since
the extra field is added to all deleters and requires an extra comparison. It is
not possible to do this using a compile-time-only mechansim because templates are
not covariant. That would prevent |owned<T, DELETE>| and |member<T, BORROW>|
from both returning a |ref<T>| even if DELETE and BORROW parameters were related.

But this also makes non-TRACK_REFS mode member<T> just a type alias for T, which
is more conceptually correct.
test.cc
test_helpers.cc
zcpointer.h