www.digitalmars.com         C & C++   DMDScript  

c++.stlsoft - [COMSTL, Adi's report] defaulting to ownership in interface pointer wrappers

reply "Matthew" <matthew hat.stlsoft.dot.org> writes:
 7. Consider making the second argument of interface_ptr<> default to
 false.  It seems to me that this would be in the spirit of RAII too.
 This would be the case when directly moving the newly received pointer
 (say from into the interface_ptr<>, without keeping an extra "bare"
 copy. (This is also related to 5 above).

*Never* going to happen, I'm afraid. This is another fatal mistake of reference counting wrappers that some other libraries have made. It is always going to bite you somewhere. Something that I've toyed with for a long time, and may yet do, is to change the bAddRef parameter from a bool to an enumeration. There's no doubt that ISomething *psomething stlsoft::ref_ptr<ISomething> something(psomething, STLSOFT_CONSUME_REF); // Eat the reference is clearer and less maintenance-fragile than: ISomething *psomething stlsoft::ref_ptr<ISomething> something(psomething, false); // Consume the reference Both are, of course, lightyears ahead of ISomething *psomething stlsoft::ref_ptr<ISomething> something(psomething); // WFT! Am I eating or copying the reference? Help! Cheers Matthew
Dec 02 2006
parent Adi Shavit <adish gentech.co.il> writes:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000099">
<font face="Verdana">ok, ok..<br>
;-)<br>
Adi<br>
</font><br>
Matthew wrote:
<blockquote cite="midekt67o$20lf$1 digitaldaemon.com" type="cite">
  <blockquote type="cite">
    <pre wrap="">7. Consider making the second argument of
interface_ptr&lt;&gt; default to
false.  It seems to me that this would be in the spirit of RAII too.
This would be the case when directly moving the newly received pointer
(say from into the interface_ptr&lt;&gt;, without keeping an extra "bare"
copy. (This is also related to 5 above).
    </pre>
  </blockquote>
  <pre wrap=""><!---->
*Never* going to happen, I'm afraid. This is another fatal mistake of
reference counting wrappers that some other libraries have made. It is
always going to bite you somewhere.

Something that I've toyed with for a long time, and may yet do, is to change
the bAddRef parameter from a bool to an enumeration. There's no doubt that

    ISomething *psomething
    stlsoft::ref_ptr&lt;ISomething&gt;  something(psomething,
STLSOFT_CONSUME_REF); // Eat the reference

is clearer and less maintenance-fragile than:

    ISomething *psomething
    stlsoft::ref_ptr&lt;ISomething&gt;  something(psomething, false); // Consume
the reference


Both are, of course, lightyears ahead of

    ISomething *psomething
    stlsoft::ref_ptr&lt;ISomething&gt;  something(psomething); // WFT! Am I
eating
or copying the reference? Help!


Cheers

Matthew


  </pre>
</blockquote>
</body>
</html>
Dec 05 2006