C++ Logo


Advanced search

Is gsl::owner usable for shared-ownership?

From: Johannes Schaub <schaub.johannes_at_[hidden]>
Date: Mon, 16 Jan 2023 12:21:24 +0100
For example, can it be used in Qt for the following?

gsl::owner<QWidget*> w{new QWidget{parent}}

In this example, the ownership is shared by the new-site and the parent,
because the code who has new-ed the object can delete w, and W's destructor
will take itself out of parent children list. However, if w is not deleted
at the new-site, then parent will delete it in its destructor. It is not
enforced by the type system that there are no new-site users left, so I'm
not sure about the ownership kind here.

   1. Is this an example of shared ownership, and
   2. can gsl::owner be used for it?

Received on 2023-01-16 11:21:37