Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2008-07-16 11:19:57


On Jul 16, 2008, at 10:43 AM, David Abrahams wrote:

>
> on Wed Jul 16 2008, Mathias Gaunard <mathias.gaunard-AT-ens-
> lyon.org> wrote:
>
>> Mathias Gaunard wrote:
>>> I personally don't see the point in dynamic deleters, they're only
>>> specializations of dynamic ones.
>>
>> I meant static ones, sorry.
>
> One point is to simplify the type information that ends up in
> interfaces.

Here's one code snippet that is likely to satisfy stability
requirements for both API and ABI that might arise over time:

struct B;

class A
{
public:
     typedef std::unique_ptr<B, void(*)(B*)> handle;
private:
     handle p_;
public:
     static void reclaim(B*); // used as the deleter

     A(); // p_ constructed with reclaim
     handle get() {return std::move(p_);}
};

int main()
{
     A a;
     A::handle p = a.get();
     // ...
} // call A::reclaim(p.get())

B's layout is hidden (can change over time). The details of how to
destruct B are hidden (and can change over time). The details of how
to create a B are hidden (and can change over time). Destruction of B
is automatic. One can pass (move) a handle (if desired) to the
resource B and still have it destructed automatically and correctly.

If one can suffer ABI changes, but not API changes, the type of the
smart pointer is hidden behind a typedef (and can change over time).

-Howard


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk