On Wed, 14 May 2008 15:11:54 CST, "Alf P. Steinbach" wrote:
>* Roland Pibinger:
>> AFAICS, you need to sup****t const and non-const arguments.
>
>Well, if conventional, straightforward notation is to be sup****ted
>then until C++0x that leads to a combinatorial explosion, e.g. 63 =
>2^(5+1)-1 constructor overloads for sup****t for 5 or fewer arguments,
>and it's very rare that a non-const constructor argument makes sense.
Non-const constructor arguments (also non-const pointers) make sense
for a generic template. I have implemented a generic factory (creates
and owns objects). Its create functions sup****t up to 8 const and
non-const arguments. You just have to write a little code generation
tool ...
>Sup****ting the possibility self-destruction, or other early
>destruction via an agency that is not the smart-pointer, is the main
>point of CheckingPtr, which AutoNewPtr builds on. For example,
>objects that represent GUI objects often self-destruct ...
>As another example, objects that represent e.g. files often enter a
>zombie state (std::istream and std::ostream objects do).
I'm not aware of those GUI frameworks (although I worked on Windows
for several years) nor of i/ostream zombie states. Anyway,
AutoNewPtr's main point, at least for me, is that it is "not
initialized with a raw pointer" and "takes responsibility for 'new'".
>
>Where you want a default-constructed pointee, the AutoNewPtr notation
>is therefore to say that explicitly,
>
> AutoNewPtr<T> p( newNoArgs ); // Like p = new T;
The constructor syntax in general seems to be problematic.
AutoNewPtr<T> represents a pointer (and accesses T like a pointer) but
is constructed as if it were an object on the stack. Create functions
instead of constructors would be more consistent, e.g.:
AutoNewPtr<T> p1 = createAutoNewPtr<T>(); // like p1 = new T
p1->dosomething();
AutoNewPtr<T> p2; // like p2 = 0
AutoNewPtr<T> p3 = createAutoNewPtr<T>(arg); // like p3 = new T(arg)
>The deleter customization ability is the to-be-standard
>std::default_delete mechanism, illustrated in the test code.
I've not been aware of 'default_delete' (frankly, I'm not interested
in C++ 0x).
I see at least two advantages of an AutoNewPtr-like template compared
to conventional 'smart pointers' (disregarding self-destructing
objects for the sake of argument):
- clear owner****p semantics, no transfer of owner****p
- only one call of operator new per created object is necessary
(object and ref-counter can be allocated together), i.e. the
efficiency of auto_ptr combined with the semantics of shared_ptr.
--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|