🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #469

Re: Asymmetry: "new (placement) T" vs. "Tptr->~T"

#469
From: Andrew Koenig
Date: Thu, 30 Aug 1990 19:23
41 lines
1978 bytes
In article <620@dlogics.COM>, jmd@dlogics.COM (Jens M. Dill) writes:

> Is anyone else bothered by the inherent asymmetry in the application of
> constructors and destructors to an object that is to reside in a known
> memory location?

The asymmetry is an intrinsic part of the operation.  In one case
you're taking raw memory and building an object.  In the other,
you're destroying an object that already exists.

> To undo this, one is supposed to apply the destructor ~T explicitly:

>             Tptr->~T () ;

> This is all very well if one knows whether or not T is a class with a
> destructor, but consider the case where T is a type argument to a template
> (or to a macro that emulates the template facility).  In this case, one
> cannot know if T is a type with constructors or destructors, since that
> information is unavailable until T is bound in a template-class definition.

Yes, that is indeed a problem.  The original article suggested several
solutions, and one of those has actually been written into the manual.

See Ellis & Stroustrup, page 280:

	The notation for explicit call of a destructor
	may be used for any simple type name.  For example:

		int* p;
		// ...
		p->int::~int();
	
	Using the notation for a type that does not have a
	destructor has no effect.  Allowing this enables people
	to write code without having to know if a destructor
	exists for a given type.

This isn't implemented everywhere yet, but I hope it will be.
-- 
				--Andrew Koenig
				  ark@europa.att.com
Technical Details
Message-ID: <11256@alice.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!dptg!ulysses!andante!alice!ark
References: <620@dlogics.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!dptg!ulysses!andante!alice!ark
From: ark@alice.UUCP (Andrew Koenig)
Newsgroups: comp.std.c++
Subject: Re: Asymmetry: "new (placement) T"  vs. "Tptr->~T"
Keywords: placement new delete constructor destructor template
Message-ID: <11256@alice.UUCP>
Date: 30 Aug 90 19:23:27 GMT
References: <620@dlogics.COM>
Organization: AT&T Bell Laboratories, Liberty Corner NJ
Lines: 41