Boost logo

Boost :

From: Jeffrey D. Paquette (paquette_at_[hidden])
Date: 2000-04-30 11:22:22

Ah, yes, I missed that! My intent was to prevent misuse-by-misunderstanding,
but since those same programmers would slap a :: to new (since half of them
do a global 'using namespace std;') and defeat the mechanism anyway.

Well, my goal was to learn something...

Thanks for your input.

Jeff Paquette
paquette_at_[hidden], paquette_at_[hidden]
-----Original Message-----
From: Saul Tamari [mailto:saul_tamari_at_[hidden]]
Sent: Sunday, April 30, 2000 1:34 AM
To: 'boost_at_[hidden]'
Subject: [boost] RE: class nonallocatable
Importance: High
I think that even though you declared the various new & delete operators to
be private, a user may still dynamicaly allocate an object of your class
using the global new.
> ----------
> From: 	Jeffrey D. Paquette
> Reply To: 	boost_at_[hidden]
> Sent: 	Saturday, April 29, 2000 3:06 PM
> To: 	boost_at_[hidden]
> Subject: 	[boost] Proposal: class nonallocatable
> I've been following this group for a few months now and have seen several
> variations of scoped utility classes fly by (shared_ptr, deferred_value,
> etc) and it seems that all of these classes, including a few that I've
> written have one drawback that can lead to misuse: they all can be
> dynamically allocated, thus bypassing the intent of the class.
> So, in the spirit of noncopyable, here is a first cut at nonallocatable:
> class nonallocatable {
> private:
>   // single instance new and delete
>   void *operator new(size_t);
>   void operator delete(void *);
>   void *operator new(size_t, const std::nothrow_t&) throw ();
>   void operator delete(void *, const std::nothrow_t&) throw ();
>   // array new and delete
>   void *operator new[](size_t);
>   void operator delete[](void *);
>   void *operator new[](size_t, const std::nothrow_t&) throw ();
>   void operator delete[](void *, const std::nothrow_t&) throw ();
>   // placement new and delete
>   void *operator new(size_t, void *) throw ();
>   void operator delete(void *, void *) throw ();
>   void *operator new[](size_t, void *) throw ();
>   void operator delete[](void *, void *) throw ();
> };
> The idea is to derive scope-helper classes from nonallocatable, thus
> preventing the misuse of these classes, like so:
Accurate impartial advice on everything from laptops to table saws.

Boost list run by bdawes at, gregod at, cpdaniel at, john at