C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: DestructorConstructor - a class destructor with parameter
From: Maciej Polanski (maciejpolanski75_at_[hidden])
Date: 2021-02-12 06:42:53


On 2021-02-11 20:02, Edward Catmur via Std-Discussion wrote:
> This would operate very similarly to the current proposal, but with
> the possibly unintuitive difference that the new object is being
> passed as the parameter, so that e.g. ~c(x.c) initializes x.c with the
> value of c. Furthermore, it would require re-inventing syntax to allow
> for move construction of subobjects.

While approaches "Constructor that destructs its argument" and
"Destructor that constructs its argument" seems to be just symmetrical,
my DestrcutorConstructor would have one more feature: it allows
"destructing move" depositing object's data in object of other class, or
even a function.

So without judging if this is worth efforts or not, I'd like to
highlight this part of my proposal:

//------
// class to receive data from object being deleted
class cDataSink {
public:
 Â Â Â  TakeOverData(cSomeData*);
}

// class that can be deleted with real zero-additional-cost transfer of
data:
class C {
 Â Â Â  cSomeData *pDdata;

public:
 Â Â Â  ~C(cDataSink* sink) { sink->TakeOverData(data); }    // <-
DepositingDestructor here
 Â Â Â  ~C() { delete pData; }                               // Normal
destructor
};
//------

Regards,
Maciej


STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups