|
Boost : |
From: David Abrahams (abrahams_at_[hidden])
Date: 2000-08-21 19:31:40
No opinion on whether we should have this or not, but just let me point out
that it is very different from noncopyable in two important respects:
1. noncopyable can be used when no sensible copy semantics exist. There is
simply no analogue for dynamic construction. If it makes sense to write
X x;
then it also makes sense to say
std::auto_ptr<X> x(new X);
2. noncopyable prevents copying even when the type in question is a
subobject. nonnewable can't prevent dynamic allocation as a subobject.
-Dave
P.S. No, the destructor shouldn't be virtual.
P.P.S. nonnewable doesn't prevent the use of placement new into dynamically
allocated memory
----- Original Message -----
From: "Daryle Walker" <darylew_at_[hidden]>
To: "Boost" <boost_at_[hidden]>
Sent: Monday, August 21, 2000 7:44 PM
Subject: [boost] A nonnewable class
> Should we have a "nonnewable" class? It is similar to noncopyable, but it
> bans new and delete instead. Here's a quick mock-up:
>
>
//==========================================================================
> namespace boost
> {
> //...
>
> class nonnewable
> {
> protected:
> nonnewable() {}
> ~nonnewable() {} // should this be virtual?
>
> private:
> void * operator new( std::size_t );
> void operator delete( void *, std::size_t );
> void * operator new[]( std::size_t );
> void operator delete[]( void *, std::size_t );
> };
>
> //...
> }
>
//==========================================================================
>
> Would this prevent someone from creating an object of this class
> dynamically? Which header should this class go into (maybe
"utility.hpp")?
> Can anyone come up with a better name? I heard that some compilers can't
> currently handle the array operators above, should we add a Boost #define
to
> block those operators, and what should they be called?
>
> --
>
>
>
>
>
>
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk