Topic: Add operator&() to std::unique_ptr to get


Author: Tony V E <tvaneerd@gmail.com>
Date: Wed, 11 Apr 2018 18:30:50 -0400
Raw View
--000000000000fcec0605699a30f1
Content-Type: text/plain; charset="UTF-8"

On Wed, Apr 11, 2018 at 6:22 PM, <thestorm.nik@gmail.com> wrote:

> Hello,
>
> There are many old APIs that are using double pointer as argument to
> return an object. Wide usage examples are WinAPI, SDL, etc.
> Currently you have to use one more temporary variable to pass it and then
> assign it to std::unique_ptr.
>
> *// Some utility header file...*
> *struct ComCloser*
> *{*
> * constexpr ComCloser() noexcept = default;*
> * void operator()( IUnknown* comObj ) noexcept*
> * {*
> * comObj->Release();*
> * }*
> *};*
>
> *template<typename T>*
> *using ComResource = std::unique_ptr<T, ComCloser>;*
>
> *// Some cpp file*
> *IWbemLocator* pLoc = nullptr;*
> *HRESULT hres = CoCreateInstance( CLSID_WbemLocator, 0,
> CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&pLoc );*
> *_com_util::CheckError( hres ); // will throw exception on error*
>
> *ComResource<IWbemLocator> locator( pLoc );*
>
> By adding
> *pointer* operator&()*
> *{*
>
> * reset();*
> * return &_ptr;*
> *}*
>
> We can omit most of the cpp file code to become like
> *// Some cpp file*
> *ComResource<IWbemLocator> locator;*
> *HRESULT hres = ::CoCreateInstance( CLSID_WbemLocator, 0,
> CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&locator );*
> *_com_util::CheckError( hres );*
>
> Of course when using operator&() if there is any previous pointer it will
> be destroyed by reset(); as it can be seen from my example.
> Please provide feedback and suggestions. :)
>


Most of the committee hates that you can overload operator&, particularly
the library implementors, who need to sprinkle std::addressof() everywhere
to fight against it.


--
Be seeing you,
Tony

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAOHCbit6AaHgy6wWPJrT5E1bRSjYgRe_VP6OCyAn1YdhoyJS9w%40mail.gmail.com.

--000000000000fcec0605699a30f1
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><div class=3D"gmail_quo=
te">On Wed, Apr 11, 2018 at 6:22 PM,  <span dir=3D"ltr">&lt;<a href=3D"mail=
to:thestorm.nik@gmail.com" target=3D"_blank">thestorm.nik@gmail.com</a>&gt;=
</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .=
8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Hello,<di=
v><br></div><div>There are many old APIs that are using double pointer as a=
rgument to return an object. Wide usage examples are WinAPI, SDL, etc.</div=
><div>Currently you have to use one more temporary variable to pass it and =
then assign it to std::unique_ptr.</div><div><br></div><div><div><i>// Some=
 utility header file...</i></div><div><i>struct ComCloser</i></div><div><i>=
{</i></div><div><i><span style=3D"white-space:pre-wrap"> </span>constexpr C=
omCloser() noexcept =3D default;</i></div><div><i><span style=3D"white-spac=
e:pre-wrap"> </span>void operator()( IUnknown* comObj ) noexcept</i></div><=
div><i><span style=3D"white-space:pre-wrap"> </span>{</i></div><div><i><spa=
n style=3D"white-space:pre-wrap">  </span>comObj-&gt;Release();</i></div><d=
iv><i><span style=3D"white-space:pre-wrap"> </span>}</i></div><div><i>};</i=
></div><div><i><br></i></div><div><i>template&lt;typename T&gt;</i></div><d=
iv><i>using ComResource =3D std::unique_ptr&lt;T, ComCloser&gt;;</i></div><=
div><i><br></i></div><div><i>// Some cpp file</i></div><div><i>IWbemLocator=
* pLoc =3D nullptr;</i></div><div><i>HRESULT hres =3D CoCreateInstance( CLS=
ID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&amp;pL=
oc );</i></div><div><i>_com_util::CheckError( hres ); // will throw excepti=
on on error</i></div><div><i><br></i></div><div><i>ComResource&lt;IWbemLoca=
tor&gt; locator( pLoc );</i></div></div><div><br></div><div>By adding</div>=
<div><div><i>pointer* operator&amp;()</i></div><div><i>{</i></div><div><i><=
span style=3D"white-space:pre-wrap"> </span>reset();<br></i></div><div><i><=
span style=3D"white-space:pre-wrap"> </span>return &amp;_ptr;</i></div><div=
><i>}</i></div></div><div><br></div><div>We can omit most of the cpp file c=
ode to become like</div><div><div><i>// Some cpp file</i></div><div><i>ComR=
esource&lt;IWbemLocator&gt; locator;</i></div><div><i>HRESULT hres =3D ::Co=
CreateInstance( CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocato=
r, (LPVOID*)&amp;locator );</i></div><div><i>_com_util::CheckError( hres );=
</i></div></div><div><br></div><div>Of course when using operator&amp;() if=
 there is any previous pointer it will be destroyed by reset(); as it can b=
e seen from my example.</div><div>Please provide feedback and suggestions. =
:)</div></div></blockquote><div><br><br></div></div>Most of the committee h=
ates that you can overload operator&amp;, particularly the library implemen=
tors, who need to sprinkle std::addressof() everywhere to fight against it.=
<br></div><br><div class=3D"gmail_extra"><br>-- <br><div class=3D"gmail_sig=
nature" data-smartmail=3D"gmail_signature"><div dir=3D"ltr"><div>Be seeing =
you,<br></div>Tony<br></div></div>
</div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAOHCbit6AaHgy6wWPJrT5E1bRSjYgRe_VP6O=
CyAn1YdhoyJS9w%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAOHCbit6AaHgy6wW=
PJrT5E1bRSjYgRe_VP6OCyAn1YdhoyJS9w%40mail.gmail.com</a>.<br />

--000000000000fcec0605699a30f1--

.


Author: thestorm.nik@gmail.com
Date: Wed, 11 Apr 2018 15:35:12 -0700 (PDT)
Raw View
------=_Part_1725_672811522.1523486112382
Content-Type: multipart/alternative;
 boundary="----=_Part_1726_1484136580.1523486112383"

------=_Part_1726_1484136580.1523486112383
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Ok, It's fine for me to be just a regular method. The general idea is more=
=20
important here.

=D1=87=D0=B5=D1=82=D0=B2=D1=8A=D1=80=D1=82=D1=8A=D0=BA, 12 =D0=B0=D0=BF=D1=
=80=D0=B8=D0=BB 2018 =D0=B3., 1:30:53 UTC+3, Tony V E =D0=BD=D0=B0=D0=BF=D0=
=B8=D1=81=D0=B0:
>
>
>
> On Wed, Apr 11, 2018 at 6:22 PM, <thesto...@gmail.com <javascript:>>=20
> wrote:
>
>> Hello,
>>
>> There are many old APIs that are using double pointer as argument to=20
>> return an object. Wide usage examples are WinAPI, SDL, etc.
>> Currently you have to use one more temporary variable to pass it and the=
n=20
>> assign it to std::unique_ptr.
>>
>> *// Some utility header file...*
>> *struct ComCloser*
>> *{*
>> * constexpr ComCloser() noexcept =3D default;*
>> * void operator()( IUnknown* comObj ) noexcept*
>> * {*
>> * comObj->Release();*
>> * }*
>> *};*
>>
>> *template<typename T>*
>> *using ComResource =3D std::unique_ptr<T, ComCloser>;*
>>
>> *// Some cpp file*
>> *IWbemLocator* pLoc =3D nullptr;*
>> *HRESULT hres =3D CoCreateInstance( CLSID_WbemLocator, 0,=20
>> CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&pLoc );*
>> *_com_util::CheckError( hres ); // will throw exception on error*
>>
>> *ComResource<IWbemLocator> locator( pLoc );*
>>
>> By adding
>> *pointer* operator&()*
>> *{*
>>
>> * reset();*
>> * return &_ptr;*
>> *}*
>>
>> We can omit most of the cpp file code to become like
>> *// Some cpp file*
>> *ComResource<IWbemLocator> locator;*
>> *HRESULT hres =3D ::CoCreateInstance( CLSID_WbemLocator, 0,=20
>> CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&locator );*
>> *_com_util::CheckError( hres );*
>>
>> Of course when using operator&() if there is any previous pointer it wil=
l=20
>> be destroyed by reset(); as it can be seen from my example.
>> Please provide feedback and suggestions. :)
>>
>
>
> Most of the committee hates that you can overload operator&, particularly=
=20
> the library implementors, who need to sprinkle std::addressof() everywher=
e=20
> to fight against it.
>
>
> --=20
> Be seeing you,
> Tony
>

--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/d86a203b-ca5e-43f1-8783-5d0d76f079d8%40isocpp.or=
g.

------=_Part_1726_1484136580.1523486112383
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Ok, It&#39;s fine for me to be just a regular method. The =
general idea is more important here.<br><br>=D1=87=D0=B5=D1=82=D0=B2=D1=8A=
=D1=80=D1=82=D1=8A=D0=BA, 12 =D0=B0=D0=BF=D1=80=D0=B8=D0=BB 2018 =D0=B3., 1=
:30:53 UTC+3, Tony V E =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0:<blockquote cla=
ss=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #=
ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><br><div><br><div class=3D"g=
mail_quote">On Wed, Apr 11, 2018 at 6:22 PM,  <span dir=3D"ltr">&lt;<a href=
=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"qyViqkIdCAAJ" r=
el=3D"nofollow" onmousedown=3D"this.href=3D&#39;javascript:&#39;;return tru=
e;" onclick=3D"this.href=3D&#39;javascript:&#39;;return true;">thesto...@gm=
ail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D=
"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D=
"ltr">Hello,<div><br></div><div>There are many old APIs that are using doub=
le pointer as argument to return an object. Wide usage examples are WinAPI,=
 SDL, etc.</div><div>Currently you have to use one more temporary variable =
to pass it and then assign it to std::unique_ptr.</div><div><br></div><div>=
<div><i>// Some utility header file...</i></div><div><i>struct ComCloser</i=
></div><div><i>{</i></div><div><i><span style=3D"white-space:pre-wrap"> </s=
pan>constexpr ComCloser() noexcept =3D default;</i></div><div><i><span styl=
e=3D"white-space:pre-wrap"> </span>void operator()( IUnknown* comObj ) noex=
cept</i></div><div><i><span style=3D"white-space:pre-wrap"> </span>{</i></d=
iv><div><i><span style=3D"white-space:pre-wrap">  </span>comObj-&gt;Release=
();</i></div><div><i><span style=3D"white-space:pre-wrap"> </span>}</i></di=
v><div><i>};</i></div><div><i><br></i></div><div><i>template&lt;typename T&=
gt;</i></div><div><i>using ComResource =3D std::unique_ptr&lt;T, ComCloser&=
gt;;</i></div><div><i><br></i></div><div><i>// Some cpp file</i></div><div>=
<i>IWbemLocator* pLoc =3D nullptr;</i></div><div><i>HRESULT hres =3D CoCrea=
teInstance( CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (=
LPVOID*)&amp;pLoc );</i></div><div><i>_com_util::CheckError( hres ); // wil=
l throw exception on error</i></div><div><i><br></i></div><div><i>ComResour=
ce&lt;IWbemLocator&gt; locator( pLoc );</i></div></div><div><br></div><div>=
By adding</div><div><div><i>pointer* operator&amp;()</i></div><div><i>{</i>=
</div><div><i><span style=3D"white-space:pre-wrap"> </span>reset();<br></i>=
</div><div><i><span style=3D"white-space:pre-wrap"> </span>return &amp;_ptr=
;</i></div><div><i>}</i></div></div><div><br></div><div>We can omit most of=
 the cpp file code to become like</div><div><div><i>// Some cpp file</i></d=
iv><div><i>ComResource&lt;IWbemLocator&gt; locator;</i></div><div><i>HRESUL=
T hres =3D ::CoCreateInstance( CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, =
IID_IWbemLocator, (LPVOID*)&amp;locator );</i></div><div><i>_com_util::Chec=
kError( hres );</i></div></div><div><br></div><div>Of course when using ope=
rator&amp;() if there is any previous pointer it will be destroyed by reset=
(); as it can be seen from my example.</div><div>Please provide feedback an=
d suggestions. :)</div></div></blockquote><div><br><br></div></div>Most of =
the committee hates that you can overload operator&amp;, particularly the l=
ibrary implementors, who need to sprinkle std::addressof() everywhere to fi=
ght against it.<br></div><br><div><br>-- <br><div><div dir=3D"ltr"><div>Be =
seeing you,<br></div>Tony<br></div></div>
</div></div>
</blockquote></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/d86a203b-ca5e-43f1-8783-5d0d76f079d8%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/d86a203b-ca5e-43f1-8783-5d0d76f079d8=
%40isocpp.org</a>.<br />

------=_Part_1726_1484136580.1523486112383--

------=_Part_1725_672811522.1523486112382--

.


Author: Richard Smith <richard@metafoo.co.uk>
Date: Thu, 12 Apr 2018 09:43:18 +0000
Raw View
--0000000000007c7e240569a39657
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Wed, 11 Apr 2018, 23:35 , <thestorm.nik@gmail.com> wrote:

> Ok, It's fine for me to be just a regular method. The general idea is mor=
e
> important here.
>
> =D1=87=D0=B5=D1=82=D0=B2=D1=8A=D1=80=D1=82=D1=8A=D0=BA, 12 =D0=B0=D0=BF=
=D1=80=D0=B8=D0=BB 2018 =D0=B3., 1:30:53 UTC+3, Tony V E =D0=BD=D0=B0=D0=BF=
=D0=B8=D1=81=D0=B0:
>>
>>
>>
>> On Wed, Apr 11, 2018 at 6:22 PM, <thesto...@gmail.com> wrote:
>>
>>> Hello,
>>>
>>> There are many old APIs that are using double pointer as argument to
>>> return an object. Wide usage examples are WinAPI, SDL, etc.
>>> Currently you have to use one more temporary variable to pass it and
>>> then assign it to std::unique_ptr.
>>>
>>> *// Some utility header file...*
>>> *struct ComCloser*
>>> *{*
>>> * constexpr ComCloser() noexcept =3D default;*
>>> * void operator()( IUnknown* comObj ) noexcept*
>>> * {*
>>> * comObj->Release();*
>>> * }*
>>> *};*
>>>
>>> *template<typename T>*
>>> *using ComResource =3D std::unique_ptr<T, ComCloser>;*
>>>
>>> *// Some cpp file*
>>> *IWbemLocator* pLoc =3D nullptr;*
>>> *HRESULT hres =3D CoCreateInstance( CLSID_WbemLocator, 0,
>>> CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&pLoc );*
>>> *_com_util::CheckError( hres ); // will throw exception on error*
>>>
>>> *ComResource<IWbemLocator> locator( pLoc );*
>>>
>>> By adding
>>> *pointer* operator&()*
>>> *{*
>>>
>>> * reset();*
>>> * return &_ptr;*
>>> *}*
>>>
>>> We can omit most of the cpp file code to become like
>>> *// Some cpp file*
>>> *ComResource<IWbemLocator> locator;*
>>> *HRESULT hres =3D ::CoCreateInstance( CLSID_WbemLocator, 0,
>>> CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&locator );*
>>> *_com_util::CheckError( hres );*
>>>
>>
Why not write your own wrapper type that holds an LPVOID p and a
ComResource&r, and calls r.reset(p) in its destructor, used like this:

*HRESULT hres =3D ::CoCreateInstance( CLSID_WbemLocator, 0,
CLSCTX_INPROC_SERVER, IID_IWbemLocator, OutputPointerTo(locator) );*

Of course when using operator&() if there is any previous pointer it will
>>> be destroyed by reset(); as it can be seen from my example.
>>> Please provide feedback and suggestions. :)
>>>
>>
>>
>> Most of the committee hates that you can overload operator&, particularl=
y
>> the library implementors, who need to sprinkle std::addressof() everywhe=
re
>> to fight against it.
>>
>>
>> --
>> Be seeing you,
>> Tony
>>
> --
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> To view this discussion on the web visit
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/d86a203b-ca5=
e-43f1-8783-5d0d76f079d8%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/d86a203b-ca=
5e-43f1-8783-5d0d76f079d8%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoot=
er>
> .
>

--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/CAOfiQqmnzYOZz_0BHp51Gp-_x2ZK1fYxqCRq1HVyMhQLZ_v=
bXQ%40mail.gmail.com.

--0000000000007c7e240569a39657
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"auto"><div><div class=3D"gmail_quote"><div dir=3D"ltr">On Wed, =
11 Apr 2018, 23:35 , &lt;<a href=3D"mailto:thestorm.nik@gmail.com">thestorm=
..nik@gmail.com</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" st=
yle=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div =
dir=3D"ltr">Ok, It&#39;s fine for me to be just a regular method. The gener=
al idea is more important here.<br><br>=D1=87=D0=B5=D1=82=D0=B2=D1=8A=D1=80=
=D1=82=D1=8A=D0=BA, 12 =D0=B0=D0=BF=D1=80=D0=B8=D0=BB 2018 =D0=B3., 1:30:53=
 UTC+3, Tony V E =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0:<blockquote class=3D"=
gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid=
;padding-left:1ex"><div dir=3D"ltr"><br><div><br><div class=3D"gmail_quote"=
>On Wed, Apr 11, 2018 at 6:22 PM,  <span dir=3D"ltr">&lt;<a rel=3D"nofollow=
 noreferrer">thesto...@gmail.com</a>&gt;</span> wrote:<br><blockquote class=
=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd=
ing-left:1ex"><div dir=3D"ltr">Hello,<div><br></div><div>There are many old=
 APIs that are using double pointer as argument to return an object. Wide u=
sage examples are WinAPI, SDL, etc.</div><div>Currently you have to use one=
 more temporary variable to pass it and then assign it to std::unique_ptr.<=
/div><div><br></div><div><div><i>// Some utility header file...</i></div><d=
iv><i>struct ComCloser</i></div><div><i>{</i></div><div><i><span style=3D"w=
hite-space:pre-wrap"> </span>constexpr ComCloser() noexcept =3D default;</i=
></div><div><i><span style=3D"white-space:pre-wrap"> </span>void operator()=
( IUnknown* comObj ) noexcept</i></div><div><i><span style=3D"white-space:p=
re-wrap"> </span>{</i></div><div><i><span style=3D"white-space:pre-wrap">  =
</span>comObj-&gt;Release();</i></div><div><i><span style=3D"white-space:pr=
e-wrap"> </span>}</i></div><div><i>};</i></div><div><i><br></i></div><div><=
i>template&lt;typename T&gt;</i></div><div><i>using ComResource =3D std::un=
ique_ptr&lt;T, ComCloser&gt;;</i></div><div><i><br></i></div><div><i>// Som=
e cpp file</i></div><div><i>IWbemLocator* pLoc =3D nullptr;</i></div><div><=
i>HRESULT hres =3D CoCreateInstance( CLSID_WbemLocator, 0, CLSCTX_INPROC_SE=
RVER, IID_IWbemLocator, (LPVOID*)&amp;pLoc );</i></div><div><i>_com_util::C=
heckError( hres ); // will throw exception on error</i></div><div><i><br></=
i></div><div><i>ComResource&lt;IWbemLocator&gt; locator( pLoc );</i></div><=
/div><div><br></div><div>By adding</div><div><div><i>pointer* operator&amp;=
()</i></div><div><i>{</i></div><div><i><span style=3D"white-space:pre-wrap"=
> </span>reset();<br></i></div><div><i><span style=3D"white-space:pre-wrap"=
> </span>return &amp;_ptr;</i></div><div><i>}</i></div></div><div><br></div=
><div>We can omit most of the cpp file code to become like</div><div><div><=
i>// Some cpp file</i></div><div><i>ComResource&lt;IWbemLocator&gt; locator=
;</i></div><div><i>HRESULT hres =3D ::CoCreateInstance( CLSID_WbemLocator, =
0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&amp;locator );</i></di=
v><div><i>_com_util::CheckError( hres );</i></div></div></div></blockquote>=
</div></div></div></blockquote></div></blockquote></div></div><div dir=3D"a=
uto"><br></div><div dir=3D"auto">Why not write your own wrapper type that h=
olds an LPVOID p and a ComResource&amp;r, and calls r.reset(p) in its destr=
uctor, used like this:</div><div dir=3D"auto"><br></div><div dir=3D"auto"><=
div style=3D"font-family:sans-serif" dir=3D"auto"><i>HRESULT hres =3D ::CoC=
reateInstance( CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator=
, OutputPointerTo(locator) );</i></div></div><div dir=3D"auto"><br></div><d=
iv dir=3D"auto"><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote=
" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><=
div dir=3D"ltr"><blockquote class=3D"gmail_quote" style=3D"margin:0;margin-=
left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><d=
iv><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"ma=
rgin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"lt=
r"><div>Of course when using operator&amp;() if there is any previous point=
er it will be destroyed by reset(); as it can be seen from my example.</div=
><div>Please provide feedback and suggestions. :)</div></div></blockquote><=
div><br><br></div></div>Most of the committee hates that you can overload o=
perator&amp;, particularly the library implementors, who need to sprinkle s=
td::addressof() everywhere to fight against it.<br></div><br><div><br>-- <b=
r><div><div dir=3D"ltr"><div>Be seeing you,<br></div>Tony<br></div></div>
</div></div>
</blockquote></div>

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_=
blank" rel=3D"noreferrer">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank" rel=3D"noreferrer">std-proposals@isocpp.org</a>.<br=
>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/d86a203b-ca5e-43f1-8783-5d0d76f079d8%=
40isocpp.org?utm_medium=3Demail&amp;utm_source=3Dfooter" target=3D"_blank" =
rel=3D"noreferrer">https://groups.google.com/a/isocpp.org/d/msgid/std-propo=
sals/d86a203b-ca5e-43f1-8783-5d0d76f079d8%40isocpp.org</a>.<br>
</blockquote></div></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAOfiQqmnzYOZz_0BHp51Gp-_x2ZK1fYxqCRq=
1HVyMhQLZ_vbXQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAOfiQqmnzYOZz_0B=
Hp51Gp-_x2ZK1fYxqCRq1HVyMhQLZ_vbXQ%40mail.gmail.com</a>.<br />

--0000000000007c7e240569a39657--

.


Author: "'Matt Calabrese' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Thu, 12 Apr 2018 15:24:23 +0000
Raw View
--00000000000057e1a30569a85a1c
Content-Type: text/plain; charset="UTF-8"

On Wed, Apr 11, 2018 at 6:22 PM <thestorm.nik@gmail.com> wrote:

> *pointer* operator&()*
> *{*
>
> * reset();*
> * return &_ptr;*
> *}*
>

Microsoft tried overloading operator& for something similar to this in ATL
I believe, and it has a lot of issues in my past personal experience.

First, as was mentioned, having & overloaded means that any correct code
today that uses & would break and you'd now have an address of operator
that does something other than take the address of the object. Many of us
already consider it a mistake that we even allow the address of operator to
be overloaded. Overloading that operator makes using & a "gotcha" when
inside of *any* template where the operand of & would depend on a template
parameter.

If we choose not to care about that, then we have two other problems:

First, in the Microsoft approach, there is no call to reset, iirc. This
causes the problems that you pointed out -- your Com object's Release()
function doesn't get called, so it's only safe to use when the smart
pointer is already a nullptr. Your approach attempts to go the other route
to prevent this and so it calls reset() inside of the address of operator,
but that fails if you genuinely are attempting to pass the address of the
existing target.

The core of these problems is that the proposed change is trying to use the
address of operator for something that simply is not logically taking the
address of the object. A smart pointer to Foo is *not* the same thing as a
pointer to Foo, even though they share some similarities in their interface.

If you want to work with these types you already can do so safely, and
there are some different, solid ways to simplify it if you wanted to. For
one, you can make your own version of CoCreateInstance that returns your
smart pointer type and then just call that instead. You can also just pass
in the address of an actual Com object, and then pass that into the unique
pointer. We shouldn't try to make a semantically strange address operator
for unique_ptr as an attempt to make certain, old c-ish APIs easier to use.
I'd much rather we encourage Microsoft to provide more modern APIs.

-- Matt Calabrese

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CANh8DEn4X%2BTugRixQxFpwa5P47t7SLn1xVzPyJ20hE0OeHfnKw%40mail.gmail.com.

--00000000000057e1a30569a85a1c
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_quote"><div dir=3D"ltr">On Wed, Apr 11=
, 2018 at 6:22 PM &lt;<a href=3D"mailto:thestorm.nik@gmail.com" target=3D"_=
blank">thestorm.nik@gmail.com</a>&gt; wrote:<br></div><blockquote class=3D"=
gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-=
left:1ex"><div dir=3D"ltr"><div><div><i>pointer* operator&amp;()</i></div><=
div><i>{</i></div><div><i><span style=3D"white-space:pre-wrap"> </span>rese=
t();<br></i></div><div><i><span style=3D"white-space:pre-wrap"> </span>retu=
rn &amp;_ptr;</i></div><div><i>}</i></div></div></div></blockquote><div><br=
></div><div>Microsoft tried overloading operator&amp; for something similar=
 to this in ATL I believe, and it has a lot of issues in my past personal e=
xperience.<br></div><div><br></div><div>First, as was mentioned, having &am=
p; overloaded means that any correct code today that uses &amp; would break=
 and you&#39;d now have an address of operator that does something other th=
an take the address of the object. Many of us already consider it a mistake=
 that we even allow the address of operator to be overloaded. Overloading t=
hat operator makes using &amp; a &quot;gotcha&quot; when inside of *any* te=
mplate where the operand of &amp; would depend on a template parameter.</di=
v><div><br></div><div>If we choose not to care about that, then we have two=
 other problems:=C2=A0</div><div><br></div><div>First, in the Microsoft app=
roach, there is no call to reset, iirc. This causes the problems that you p=
ointed out -- your Com object&#39;s Release() function doesn&#39;t get call=
ed, so it&#39;s only safe to use when the smart pointer is already a nullpt=
r. Your approach attempts to go the other route to prevent this and so it c=
alls reset() inside of the address of operator, but that fails if you genui=
nely are attempting to pass the address of the existing target.</div><div><=
br></div><div>The core of these problems=C2=A0is that the proposed change i=
s trying to use the address of operator for something that simply is not lo=
gically taking the address of the object. A smart pointer to Foo is *not* t=
he same thing as a pointer to Foo, even though they share some similarities=
 in their interface.</div><div><br></div><div>If you want to work with thes=
e types you already can do so safely, and there are some different, solid w=
ays to simplify it if you wanted to. For one, you can make your own version=
 of CoCreateInstance that returns your smart pointer type and then just cal=
l that instead. You can also just pass in the address of an actual Com obje=
ct, and then pass that into the unique pointer. We shouldn&#39;t try to mak=
e a semantically strange address operator for unique_ptr as an attempt to m=
ake certain, old c-ish APIs easier to use. I&#39;d much rather we encourage=
 Microsoft to provide more modern APIs.</div><div><br></div><div>-- Matt Ca=
labrese</div></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CANh8DEn4X%2BTugRixQxFpwa5P47t7SLn1xV=
zPyJ20hE0OeHfnKw%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CANh8DEn4X%2BTu=
gRixQxFpwa5P47t7SLn1xVzPyJ20hE0OeHfnKw%40mail.gmail.com</a>.<br />

--00000000000057e1a30569a85a1c--

.


Author: Richard Hodges <hodges.r@gmail.com>
Date: Thu, 12 Apr 2018 19:31:35 +0200
Raw View
--001a113ef73c9a8a290569aa20df
Content-Type: text/plain; charset="UTF-8"

Isn't it simpler and safer to simply wrap CoCreateInstance into a sanitised
function?

namespace wrap_win32
{
  template<class Interface>
  auto createInstance(REFCLSID cls, LPUNKNOWN pUnkOuter, DWORD dwClsContext
, REFIID riid)
  -> ComResource<Interface>
  {
    Interface* result = nullptr;
    auto hres = ::CoCreateInstance(cls, pUnkOuter, dwClsContext, riid,
&result);
    _com_util::CheckError( hres );
    return { result, ComCloser() };
  }
}

I think we're preferring to write functions that return results these days
rather than functions that return results while spamming side-effects all
over the place.


On 12 April 2018 at 17:24, 'Matt Calabrese' via ISO C++ Standard - Future
Proposals <std-proposals@isocpp.org> wrote:

> On Wed, Apr 11, 2018 at 6:22 PM <thestorm.nik@gmail.com> wrote:
>
>> *pointer* operator&()*
>> *{*
>>
>> * reset();*
>> * return &_ptr;*
>> *}*
>>
>
> Microsoft tried overloading operator& for something similar to this in ATL
> I believe, and it has a lot of issues in my past personal experience.
>
> First, as was mentioned, having & overloaded means that any correct code
> today that uses & would break and you'd now have an address of operator
> that does something other than take the address of the object. Many of us
> already consider it a mistake that we even allow the address of operator to
> be overloaded. Overloading that operator makes using & a "gotcha" when
> inside of *any* template where the operand of & would depend on a template
> parameter.
>
> If we choose not to care about that, then we have two other problems:
>
> First, in the Microsoft approach, there is no call to reset, iirc. This
> causes the problems that you pointed out -- your Com object's Release()
> function doesn't get called, so it's only safe to use when the smart
> pointer is already a nullptr. Your approach attempts to go the other route
> to prevent this and so it calls reset() inside of the address of operator,
> but that fails if you genuinely are attempting to pass the address of the
> existing target.
>
> The core of these problems is that the proposed change is trying to use
> the address of operator for something that simply is not logically taking
> the address of the object. A smart pointer to Foo is *not* the same thing
> as a pointer to Foo, even though they share some similarities in their
> interface.
>
> If you want to work with these types you already can do so safely, and
> there are some different, solid ways to simplify it if you wanted to. For
> one, you can make your own version of CoCreateInstance that returns your
> smart pointer type and then just call that instead. You can also just pass
> in the address of an actual Com object, and then pass that into the unique
> pointer. We shouldn't try to make a semantically strange address operator
> for unique_ptr as an attempt to make certain, old c-ish APIs easier to use.
> I'd much rather we encourage Microsoft to provide more modern APIs.
>
> -- Matt Calabrese
>
> --
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> To view this discussion on the web visit https://groups.google.com/a/
> isocpp.org/d/msgid/std-proposals/CANh8DEn4X%2BTugRixQxFpwa5P47t7SLn1xVzPyJ
> 20hE0OeHfnKw%40mail.gmail.com
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CANh8DEn4X%2BTugRixQxFpwa5P47t7SLn1xVzPyJ20hE0OeHfnKw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CALvx3hZWDV%2B%3DmvcuqtE6Asysfh2hHXUDat4nG_1DrdJHJt1v9g%40mail.gmail.com.

--001a113ef73c9a8a290569aa20df
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Isn&#39;t it simpler and safer to simply wrap CoCreateInst=
ance into a sanitised function?<div><br></div><div><div style=3D"background=
-color:rgb(255,255,254)"><div style=3D"color:rgb(0,0,0)"><font face=3D"mono=
space, monospace"><span style=3D"color:rgb(0,0,255)">namespace</span><span =
style=3D"color:rgb(0,0,0)"> wrap_win32</span></font></div><div style=3D"col=
or:rgb(0,0,0)"><span style=3D"color:rgb(0,0,0)"><font face=3D"monospace, mo=
nospace">{</font></span></div><div style=3D"color:rgb(0,0,0)"><font face=3D=
"monospace, monospace"><span style=3D"color:rgb(0,0,0)"></span><span style=
=3D"color:rgb(0,0,255)">=C2=A0 template</span><span style=3D"color:rgb(0,0,=
0)">&lt;</span><span style=3D"color:rgb(0,0,255)">class</span><span style=
=3D"color:rgb(0,0,0)"> Interface&gt;</span></font></div><div><font face=3D"=
monospace, monospace"><span style=3D"color:rgb(0,0,0)"></span><span style=
=3D"color:rgb(0,0,255)">=C2=A0 auto</span><span style=3D"color:rgb(0,0,0)">=
 createInstance(</span><font color=3D"#000000">REFCLSID cls,=C2=A0</font></=
font><font color=3D"#000000" face=3D"monospace, monospace">LPUNKNOWN pUnkOu=
ter,=C2=A0</font><font color=3D"#0000ff" style=3D"font-family:monospace,mon=
ospace">DWORD dwClsContext</font><span style=3D"font-family:monospace,monos=
pace;color:rgb(0,0,0)">,=C2=A0</span><font color=3D"#000000" style=3D"font-=
family:monospace,monospace">REFIID riid)</font></div><div style=3D"color:rg=
b(0,0,0)"><span style=3D"color:rgb(0,0,0)"><font face=3D"monospace, monospa=
ce">=C2=A0 -&gt; ComResource&lt;Interface&gt;</font></span></div><div style=
=3D"color:rgb(0,0,0)"><span style=3D"color:rgb(0,0,0)"><font face=3D"monosp=
ace, monospace">=C2=A0 {</font></span></div><div style=3D"color:rgb(0,0,0)"=
><font face=3D"monospace, monospace"><span style=3D"color:rgb(0,0,0)">=C2=
=A0 =C2=A0 Interface* result =3D </span><span style=3D"color:rgb(0,0,255)">=
nullptr</span><span style=3D"color:rgb(0,0,0)">;</span></font></div><div st=
yle=3D"color:rgb(0,0,0)"><font face=3D"monospace, monospace"><span style=3D=
"color:rgb(0,0,0)"></span><span style=3D"color:rgb(0,0,255)">=C2=A0 =C2=A0 =
auto</span><span style=3D"color:rgb(0,0,0)"> hres =3D ::CoCreateInstance(cl=
s, <span style=3D"color:rgb(0,0,0);font-family:monospace,monospace;font-siz=
e:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:n=
ormal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0p=
x;text-transform:none;white-space:normal;word-spacing:0px;background-color:=
rgb(255,255,254);text-decoration-style:initial;text-decoration-color:initia=
l;float:none;display:inline">pUnkOuter,=C2=A0</span><span style=3D"color:rg=
b(0,0,255);font-family:monospace,monospace;font-size:small;font-style:norma=
l;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;le=
tter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;wh=
ite-space:normal;word-spacing:0px;background-color:rgb(255,255,254);text-de=
coration-style:initial;text-decoration-color:initial;float:none;display:inl=
ine">dwClsContext</span>, <span style=3D"color:rgb(0,0,0);font-family:monos=
pace,monospace;font-size:small;font-style:normal;font-variant-ligatures:nor=
mal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-ali=
gn:start;text-indent:0px;text-transform:none;white-space:normal;word-spacin=
g:0px;background-color:rgb(255,255,254);text-decoration-style:initial;text-=
decoration-color:initial;float:none;display:inline">riid</span>, &amp;resul=
t);</span></font></div><div style=3D"color:rgb(0,0,0)"><span style=3D"color=
:rgb(0,0,0)"><font face=3D"monospace, monospace">=C2=A0 =C2=A0 _com_util::C=
heckError( hres );</font></span></div><div style=3D"color:rgb(0,0,0)"><font=
 face=3D"monospace, monospace"><span style=3D"color:rgb(0,0,0)"></span><spa=
n style=3D"color:rgb(0,0,255)">=C2=A0 =C2=A0 return</span><span style=3D"co=
lor:rgb(0,0,0)"> { result, ComCloser() };</span></font></div><div style=3D"=
color:rgb(0,0,0)"><span style=3D"color:rgb(0,0,0)"><font face=3D"monospace,=
 monospace">=C2=A0 }</font></span></div><div style=3D"color:rgb(0,0,0)"><sp=
an style=3D"color:rgb(0,0,0)"><font face=3D"monospace, monospace">}</font><=
/span></div><br></div>I think we&#39;re preferring to write functions that =
return results these days rather than functions that return results while s=
pamming side-effects all over the place.</div><div><br></div></div><div cla=
ss=3D"gmail_extra"><br><div class=3D"gmail_quote">On 12 April 2018 at 17:24=
, &#39;Matt Calabrese&#39; via ISO C++ Standard - Future Proposals <span di=
r=3D"ltr">&lt;<a href=3D"mailto:std-proposals@isocpp.org" target=3D"_blank"=
>std-proposals@isocpp.org</a>&gt;</span> wrote:<br><blockquote class=3D"gma=
il_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-lef=
t:1ex"><div dir=3D"ltr"><div class=3D"gmail_quote"><span class=3D""><div di=
r=3D"ltr">On Wed, Apr 11, 2018 at 6:22 PM &lt;<a href=3D"mailto:thestorm.ni=
k@gmail.com" target=3D"_blank">thestorm.nik@gmail.com</a>&gt; wrote:<br></d=
iv><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left=
:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div><i>pointer* op=
erator&amp;()</i></div><div><i>{</i></div><div><i><span style=3D"white-spac=
e:pre-wrap"> </span>reset();<br></i></div><div><i><span style=3D"white-spac=
e:pre-wrap"> </span>return &amp;_ptr;</i></div><div><i>}</i></div></div></d=
iv></blockquote><div><br></div></span><div>Microsoft tried overloading oper=
ator&amp; for something similar to this in ATL I believe, and it has a lot =
of issues in my past personal experience.<br></div><div><br></div><div>Firs=
t, as was mentioned, having &amp; overloaded means that any correct code to=
day that uses &amp; would break and you&#39;d now have an address of operat=
or that does something other than take the address of the object. Many of u=
s already consider it a mistake that we even allow the address of operator =
to be overloaded. Overloading that operator makes using &amp; a &quot;gotch=
a&quot; when inside of *any* template where the operand of &amp; would depe=
nd on a template parameter.</div><div><br></div><div>If we choose not to ca=
re about that, then we have two other problems:=C2=A0</div><div><br></div><=
div>First, in the Microsoft approach, there is no call to reset, iirc. This=
 causes the problems that you pointed out -- your Com object&#39;s Release(=
) function doesn&#39;t get called, so it&#39;s only safe to use when the sm=
art pointer is already a nullptr. Your approach attempts to go the other ro=
ute to prevent this and so it calls reset() inside of the address of operat=
or, but that fails if you genuinely are attempting to pass the address of t=
he existing target.</div><div><br></div><div>The core of these problems=C2=
=A0is that the proposed change is trying to use the address of operator for=
 something that simply is not logically taking the address of the object. A=
 smart pointer to Foo is *not* the same thing as a pointer to Foo, even tho=
ugh they share some similarities in their interface.</div><div><br></div><d=
iv>If you want to work with these types you already can do so safely, and t=
here are some different, solid ways to simplify it if you wanted to. For on=
e, you can make your own version of CoCreateInstance that returns your smar=
t pointer type and then just call that instead. You can also just pass in t=
he address of an actual Com object, and then pass that into the unique poin=
ter. We shouldn&#39;t try to make a semantically strange address operator f=
or unique_ptr as an attempt to make certain, old c-ish APIs easier to use. =
I&#39;d much rather we encourage Microsoft to provide more modern APIs.</di=
v><div><br></div><div>-- Matt Calabrese</div></div></div><span class=3D"">

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_=
blank">std-proposals+unsubscribe@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br></span>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CANh8DEn4X%2BTugRixQxFpwa5P47t7SLn1xV=
zPyJ20hE0OeHfnKw%40mail.gmail.com?utm_medium=3Demail&amp;utm_source=3Dfoote=
r" target=3D"_blank">https://groups.google.com/a/<wbr>isocpp.org/d/msgid/st=
d-<wbr>proposals/CANh8DEn4X%<wbr>2BTugRixQxFpwa5P47t7SLn1xVzPyJ<wbr>20hE0Oe=
HfnKw%40mail.gmail.com</a>.<br>
</blockquote></div><br></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CALvx3hZWDV%2B%3DmvcuqtE6Asysfh2hHXUD=
at4nG_1DrdJHJt1v9g%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CALvx3hZWDV%2=
B%3DmvcuqtE6Asysfh2hHXUDat4nG_1DrdJHJt1v9g%40mail.gmail.com</a>.<br />

--001a113ef73c9a8a290569aa20df--

.


Author: thestorm.nik@gmail.com
Date: Thu, 12 Apr 2018 11:22:16 -0700 (PDT)
Raw View
------=_Part_4469_1485602606.1523557336909
Content-Type: multipart/alternative;
 boundary="----=_Part_4470_92762737.1523557336910"

------=_Part_4470_92762737.1523557336910
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hello,

Yes, now I see that overloading operator&() is very bad idea, so let's=20
continue this discussion pretending that I proposed normal method name for=
=20
doing such thing(for example fetch_internal_ptr()).
@Richard Smith Doing such thing for CoCreateInstance will cover only one=20
case, there are much more similar API's. About Microsoft providing newer=20
API's - well even if they do we still have other legacy libraries that we=
=20
must use for some projects...
About the wrapper you proposed - yes I already use such thing

// Some header
*template<typename T, typename D>*
*class ptrptr_type*
*{*
* using parent_type =3D std::unique_ptr<T, D>;*
* using pointer =3D typename parent_type::pointer;*

*public:*
* ptrptr_type( std::unique_ptr<T, D>& ptr ) noexcept : m_parent( &ptr ),=20
m_ptr( ptr.release() )*
* {}*

* ptrptr_type( ptrptr_type&& other ) noexcept*
* {*
* *this =3D std::move( other );*
* }*

* ptrptr_type& operator=3D( ptrptr_type&& other ) noexcept*
* {*
* m_parent =3D other.m_parent;*
* m_ptr =3D other.m_ptr;*
* other.m_parent =3D nullptr;*
* return *this;*
* }*

* ~ptrptr_type() noexcept*
* {*
* if( m_parent )*
* m_parent->reset( m_ptr );*
* }*

* operator pointer*() noexcept*
* {*
* return &m_ptr;*
* }*

* operator typename std::enable_if_t<!std::is_same_v<T, void>, void**>()=20
noexcept*
* {*
* return (void**)&m_ptr;*
* }*

*private:*
* ptrptr_type( const ptrptr_type& ) =3D delete;*
* ptrptr_type& operator=3D( const ptrptr_type& ) =3D delete;*

*private:*
* parent_type* m_parent;*
* pointer m_ptr;*
*};*

*template<typename T, typename D>*
*ptrptr_type<T, D> ptrptr( std::unique_ptr<T, D>& ptr ) noexcept*
*{*
* return ptrptr_type<T, D>( ptr );*
*}*

// Some cpp
*ComResource<IWbemLocator> locator;*
*hres =3D ::CoCreateInstance( CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER,=
=20
IID_IWbemLocator, ptrptr( locator ) );*
*_com_util::CheckError( hres );*

There are many workarounds for many cases which are not or were not part of=
=20
the language or the std library. This doesn't mean that we shouldn't=20
improve it in order to make less wrappers...
If the idea for additional method(not the initial overloaded proposal) for=
=20
returning the internal pointer is not good perhaps the wrapper that I just=
=20
published is a nice idea for new feature to the std library? It can be much=
=20
more optimal if the std implementers tie it with their internal=20
implementation specific code.

=D1=87=D0=B5=D1=82=D0=B2=D1=8A=D1=80=D1=82=D1=8A=D0=BA, 12 =D0=B0=D0=BF=D1=
=80=D0=B8=D0=BB 2018 =D0=B3., 1:22:39 UTC+3, thesto...@gmail.com =D0=BD=D0=
=B0=D0=BF=D0=B8=D1=81=D0=B0:
>
> Hello,
>
> There are many old APIs that are using double pointer as argument to=20
> return an object. Wide usage examples are WinAPI, SDL, etc.
> Currently you have to use one more temporary variable to pass it and then=
=20
> assign it to std::unique_ptr.
>
> *// Some utility header file...*
> *struct ComCloser*
> *{*
> * constexpr ComCloser() noexcept =3D default;*
> * void operator()( IUnknown* comObj ) noexcept*
> * {*
> * comObj->Release();*
> * }*
> *};*
>
> *template<typename T>*
> *using ComResource =3D std::unique_ptr<T, ComCloser>;*
>
> *// Some cpp file*
> *IWbemLocator* pLoc =3D nullptr;*
> *HRESULT hres =3D CoCreateInstance( CLSID_WbemLocator, 0,=20
> CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&pLoc );*
> *_com_util::CheckError( hres ); // will throw exception on error*
>
> *ComResource<IWbemLocator> locator( pLoc );*
>
> By adding
> *pointer* operator&()*
> *{*
>
> * reset();*
> * return &_ptr;*
> *}*
>
> We can omit most of the cpp file code to become like
> *// Some cpp file*
> *ComResource<IWbemLocator> locator;*
> *HRESULT hres =3D ::CoCreateInstance( CLSID_WbemLocator, 0,=20
> CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&locator );*
> *_com_util::CheckError( hres );*
>
> Of course when using operator&() if there is any previous pointer it will=
=20
> be destroyed by reset(); as it can be seen from my example.
> Please provide feedback and suggestions. :)
>

--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/16bb5804-4557-4730-ba3b-063ba51b4764%40isocpp.or=
g.

------=_Part_4470_92762737.1523557336910
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hello,<div><br></div><div>Yes, now I see that overloading =
operator&amp;() is very bad idea, so let&#39;s continue this discussion pre=
tending that I proposed normal method name for doing such thing(for example=
 fetch_internal_ptr()).</div><div>@Richard Smith Doing such thing for CoCre=
ateInstance will cover only one case, there are much more similar API&#39;s=
.. About Microsoft providing newer API&#39;s - well even if they do we still=
 have other legacy libraries that we must use for some projects...</div><di=
v>About the wrapper you proposed - yes I already use such thing</div><div><=
br></div><div>// Some header</div><div><div><i>template&lt;typename T, type=
name D&gt;</i></div><div><i>class ptrptr_type</i></div><div><i>{</i></div><=
div><i><span style=3D"white-space:pre"> </span>using parent_type =3D std::u=
nique_ptr&lt;T, D&gt;;</i></div><div><i><span style=3D"white-space:pre"> </=
span>using pointer =3D typename parent_type::pointer;</i></div><div><i><br>=
</i></div><div><i>public:</i></div><div><i><span style=3D"white-space:pre">=
 </span>ptrptr_type( std::unique_ptr&lt;T, D&gt;&amp; ptr ) noexcept : m_pa=
rent( &amp;ptr ), m_ptr( ptr.release() )</i></div><div><i><span style=3D"wh=
ite-space:pre"> </span>{}</i></div><div><i><br></i></div><div><i><span styl=
e=3D"white-space:pre"> </span>ptrptr_type( ptrptr_type&amp;&amp; other ) no=
except</i></div><div><i><span style=3D"white-space:pre"> </span>{</i></div>=
<div><i><span style=3D"white-space:pre">  </span>*this =3D std::move( other=
 );</i></div><div><i><span style=3D"white-space:pre"> </span>}</i></div><di=
v><i><br></i></div><div><i><span style=3D"white-space:pre"> </span>ptrptr_t=
ype&amp; operator=3D( ptrptr_type&amp;&amp; other ) noexcept</i></div><div>=
<i><span style=3D"white-space:pre"> </span>{</i></div><div><i><span style=
=3D"white-space:pre">  </span>m_parent =3D other.m_parent;</i></div><div><i=
><span style=3D"white-space:pre">  </span>m_ptr =3D other.m_ptr;</i></div><=
div><i><span style=3D"white-space:pre">  </span>other.m_parent =3D nullptr;=
</i></div><div><span style=3D"white-space:pre"><i>  </i></span></div><div><=
i><span style=3D"white-space:pre">  </span>return *this;</i></div><div><i><=
span style=3D"white-space:pre"> </span>}</i></div><div><i><br></i></div><di=
v><i><span style=3D"white-space:pre"> </span>~ptrptr_type() noexcept</i></d=
iv><div><i><span style=3D"white-space:pre"> </span>{</i></div><div><i><span=
 style=3D"white-space:pre">  </span>if( m_parent )</i></div><div><i><span s=
tyle=3D"white-space:pre">   </span>m_parent-&gt;reset( m_ptr );</i></div><d=
iv><i><span style=3D"white-space:pre"> </span>}</i></div><div><i><br></i></=
div><div><i><span style=3D"white-space:pre"> </span>operator pointer*() noe=
xcept</i></div><div><i><span style=3D"white-space:pre"> </span>{</i></div><=
div><i><span style=3D"white-space:pre">  </span>return &amp;m_ptr;</i></div=
><div><i><span style=3D"white-space:pre"> </span>}</i></div><div><i><br></i=
></div><div><i><span style=3D"white-space:pre"> </span>operator typename st=
d::enable_if_t&lt;!std::is_same_v&lt;T, void&gt;, void**&gt;() noexcept</i>=
</div><div><i><span style=3D"white-space:pre"> </span>{</i></div><div><i><s=
pan style=3D"white-space:pre">  </span>return (void**)&amp;m_ptr;</i></div>=
<div><i><span style=3D"white-space:pre"> </span>}</i></div><div><i><br></i>=
</div><div><i>private:</i></div><div><i><span style=3D"white-space:pre"> </=
span>ptrptr_type( const ptrptr_type&amp; ) =3D delete;</i></div><div><i><sp=
an style=3D"white-space:pre"> </span>ptrptr_type&amp; operator=3D( const pt=
rptr_type&amp; ) =3D delete;</i></div><div><i><br></i></div><div><i>private=
:</i></div><div><i><span style=3D"white-space:pre"> </span>parent_type* m_p=
arent;</i></div><div><i><span style=3D"white-space:pre"> </span>pointer m_p=
tr;</i></div><div><i>};</i></div><div><i><br></i></div><div><i>template&lt;=
typename T, typename D&gt;</i></div><div><i>ptrptr_type&lt;T, D&gt; ptrptr(=
 std::unique_ptr&lt;T, D&gt;&amp; ptr ) noexcept</i></div><div><i>{</i></di=
v><div><i><span style=3D"white-space:pre"> </span>return ptrptr_type&lt;T, =
D&gt;( ptr );</i></div><div><i>}</i></div><div><br></div><div>// Some cpp</=
div><div><div><i>ComResource&lt;IWbemLocator&gt; locator;</i></div><div><i>=
hres =3D ::CoCreateInstance( CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, II=
D_IWbemLocator, ptrptr( locator ) );</i></div><div><i>_com_util::CheckError=
( hres );</i></div></div><div><br></div><div>There are many workarounds for=
 many cases which are not or were not part of the language or the std libra=
ry. This doesn&#39;t mean that we shouldn&#39;t improve it in order to make=
 less wrappers...</div><div>If the idea for additional method(not the initi=
al overloaded proposal) for returning the internal pointer is not good perh=
aps the wrapper that I just published is a nice idea for new feature to the=
 std library? It can be much more optimal if the std implementers tie it wi=
th their internal implementation specific code.</div><br>=D1=87=D0=B5=D1=82=
=D0=B2=D1=8A=D1=80=D1=82=D1=8A=D0=BA, 12 =D0=B0=D0=BF=D1=80=D0=B8=D0=BB 201=
8 =D0=B3., 1:22:39 UTC+3, thesto...@gmail.com =D0=BD=D0=B0=D0=BF=D0=B8=D1=
=81=D0=B0:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left:=
 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">Hel=
lo,<div><br></div><div>There are many old APIs that are using double pointe=
r as argument to return an object. Wide usage examples are WinAPI, SDL, etc=
..</div><div>Currently you have to use one more temporary variable to pass i=
t and then assign it to std::unique_ptr.</div><div><br></div><div><div><i>/=
/ Some utility header file...</i></div><div><i>struct ComCloser</i></div><d=
iv><i>{</i></div><div><i><span style=3D"white-space:pre"> </span>constexpr =
ComCloser() noexcept =3D default;</i></div><div><i><span style=3D"white-spa=
ce:pre"> </span>void operator()( IUnknown* comObj ) noexcept</i></div><div>=
<i><span style=3D"white-space:pre"> </span>{</i></div><div><i><span style=
=3D"white-space:pre">  </span>comObj-&gt;Release();</i></div><div><i><span =
style=3D"white-space:pre"> </span>}</i></div><div><i>};</i></div><div><i><b=
r></i></div><div><i>template&lt;typename T&gt;</i></div><div><i>using ComRe=
source =3D std::unique_ptr&lt;T, ComCloser&gt;;</i></div><div><i><br></i></=
div><div><i>// Some cpp file</i></div><div><i>IWbemLocator* pLoc =3D nullpt=
r;</i></div><div><i>HRESULT hres =3D CoCreateInstance( CLSID_WbemLocator, 0=
, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&amp;pLoc );</i></div><d=
iv><i>_com_util::CheckError( hres ); // will throw exception on error</i></=
div><div><i><br></i></div><div><i>ComResource&lt;IWbemLocator&gt; locator( =
pLoc );</i></div></div><div><br></div><div>By adding</div><div><div><i>poin=
ter* operator&amp;()</i></div><div><i>{</i></div><div><i><span style=3D"whi=
te-space:pre"> </span>reset();<br></i></div><div><i><span style=3D"white-sp=
ace:pre"> </span>return &amp;_ptr;</i></div><div><i>}</i></div></div><div><=
br></div><div>We can omit most of the cpp file code to become like</div><di=
v><div><i>// Some cpp file</i></div><div><i>ComResource&lt;IWbemLocator&gt;=
 locator;</i></div><div><i>HRESULT hres =3D ::CoCreateInstance( CLSID_WbemL=
ocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&amp;locator );=
</i></div><div><i>_com_util::CheckError( hres );</i></div></div><div><br></=
div><div>Of course when using operator&amp;() if there is any previous poin=
ter it will be destroyed by reset(); as it can be seen from my example.</di=
v><div>Please provide feedback and suggestions. :)</div></div></blockquote>=
</div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/16bb5804-4557-4730-ba3b-063ba51b4764%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/16bb5804-4557-4730-ba3b-063ba51b4764=
%40isocpp.org</a>.<br />

------=_Part_4470_92762737.1523557336910--

------=_Part_4469_1485602606.1523557336909--

.


Author: Zhihao Yuan <zy@miator.net>
Date: Fri, 13 Apr 2018 03:16:55 -0400
Raw View
This is a multi-part message in MIME format.

--b1_11a4af6f4e941d64b7f0ab9d7bc80095
Content-Type: text/plain; charset="UTF-8"

(LPVOID*)locator.release()

--

Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
_______________________________________________

From: thestorm.nik@gmail.com <thestorm.nik@gmail.com>
Sent: Wednesday, April 11, 2018 5:23 PM

By adding

pointer* operator&()

{

            reset();

            return &_ptr;

}

We can omit most of the cpp file code to become like

// Some cpp file

ComResource<IWbemLocator> locator;

HRESULT hres = ::CoCreateInstance( CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&locator );

_com_util::CheckError( hres );

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CVnLOCQ3RssM8X1ax1QP9S_S9tJrCrPTN8Pq6axGX1z3TbJ59r1QsxSAop0agvqzzWqmJyMGzShmaWtjk8UdW_1qFR4T9wjJaoKhe_X5cDw%3D%40miator.net.

--b1_11a4af6f4e941d64b7f0ab9d7bc80095
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<html><head></head><body><div class=3D"WordSection1"><p class=3D"MsoNormal"=
><i>(LPVOID*)locator.release()</i><o:p></o:p></p><p class=3D"MsoNormal"><o:=
p>=C2=A0</o:p></p><p class=3D"MsoNormal">--<o:p></o:p></p><p class=3D"MsoNo=
rmal">Zhihao Yuan, ID lichray<br/>The best way to predict the future is to =
invent it.<br/>_______________________________________________<o:p></o:p></=
p><p class=3D"MsoNormal"><o:p>=C2=A0</o:p></p><div style=3D"border:none;bor=
der-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt"><div><div><p class=3D"=
MsoNormal"><b>From:</b> thestorm.nik@gmail.com &lt;thestorm.nik@gmail.com&g=
t; <br/><b>Sent:</b> Wednesday, April 11, 2018 5:23 PM<br/><br/><o:p></o:p>=
</p></div><div><p class=3D"MsoNormal">By adding<o:p></o:p></p></div><div><d=
iv><p class=3D"MsoNormal"><i>pointer* operator&amp;()</i><o:p></o:p></p></d=
iv><div><p class=3D"MsoNormal"><i>{</i><o:p></o:p></p></div><div><p class=
=3D"MsoNormal"><i>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 reset();</i><o:p></o:p></p></div><div><p class=3D"MsoNormal"><i>=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return &=
amp;_ptr;</i><o:p></o:p></p></div><div><p class=3D"MsoNormal"><i>}</i><o:p>=
</o:p></p></div></div><div><p class=3D"MsoNormal"><o:p>=C2=A0</o:p></p></di=
v><div><p class=3D"MsoNormal">We can omit most of the cpp file code to beco=
me like<o:p></o:p></p></div><div><div><p class=3D"MsoNormal"><i>// Some cpp=
 file</i><o:p></o:p></p></div><div><p class=3D"MsoNormal"><i>ComResource&lt=
;IWbemLocator&gt; locator;</i><o:p></o:p></p></div><div><p class=3D"MsoNorm=
al"><i>HRESULT hres =3D ::CoCreateInstance( CLSID_WbemLocator, 0, CLSCTX_IN=
PROC_SERVER, IID_IWbemLocator, (LPVOID*)&amp;locator );</i><o:p></o:p></p><=
/div></div></div><div><p class=3D"MsoNormal"><i>_com_util::CheckError( hres=
 );</i><o:p></o:p></p></div></div></div></body></html>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CVnLOCQ3RssM8X1ax1QP9S_S9tJrCrPTN8Pq6=
axGX1z3TbJ59r1QsxSAop0agvqzzWqmJyMGzShmaWtjk8UdW_1qFR4T9wjJaoKhe_X5cDw%3D%4=
0miator.net?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CVnLOCQ3RssM8X1ax1QP9S_S9tJrCrPTN8Pq6=
axGX1z3TbJ59r1QsxSAop0agvqzzWqmJyMGzShmaWtjk8UdW_1qFR4T9wjJaoKhe_X5cDw%3D%4=
0miator.net</a>.<br />

--b1_11a4af6f4e941d64b7f0ab9d7bc80095--


.


Author: phdofthehouse@gmail.com
Date: Sun, 15 Apr 2018 16:42:30 -0700 (PDT)
Raw View
------=_Part_19782_1666191677.1523835750683
Content-Type: multipart/alternative;
 boundary="----=_Part_19783_1125167956.1523835750683"

------=_Part_19783_1125167956.1523835750683
Content-Type: text/plain; charset="UTF-8"

This has actually come up more times than I initially thought. There are
TONS of companies who have this abstraction internally, and also tons of
people who write this code externally on their own as well.

So, I put it in library form, consumable in CMake, and also enhanced it so
that it is usable with `std::shared_ptr`, `boost::shared_ptr`, and
(hopefully) with the upcoming `std::retain_ptr`:

https://github.com/ThePhD/ptrptr

Of note here is the benchmarks. I plan to actually write a blog post about
this, because it seems there is some performance left on the table when
going through the typical .release() + .reset() route with a
`std::unique_ptr`, which makes this more than just "nice" to have in the
standard library.

On Wednesday, April 11, 2018 at 6:22:39 PM UTC-4, thesto...@gmail.com wrote:
>
> Hello,
>
> There are many old APIs that are using double pointer as argument to
> return an object. Wide usage examples are WinAPI, SDL, etc.
> Currently you have to use one more temporary variable to pass it and then
> assign it to std::unique_ptr.
>
> *// Some utility header file...*
> *struct ComCloser*
> *{*
> * constexpr ComCloser() noexcept = default;*
> * void operator()( IUnknown* comObj ) noexcept*
> * {*
> * comObj->Release();*
> * }*
> *};*
>
> *template<typename T>*
> *using ComResource = std::unique_ptr<T, ComCloser>;*
>
> *// Some cpp file*
> *IWbemLocator* pLoc = nullptr;*
> *HRESULT hres = CoCreateInstance( CLSID_WbemLocator, 0,
> CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&pLoc );*
> *_com_util::CheckError( hres ); // will throw exception on error*
>
> *ComResource<IWbemLocator> locator( pLoc );*
>
> By adding
> *pointer* operator&()*
> *{*
>
> * reset();*
> * return &_ptr;*
> *}*
>
> We can omit most of the cpp file code to become like
> *// Some cpp file*
> *ComResource<IWbemLocator> locator;*
> *HRESULT hres = ::CoCreateInstance( CLSID_WbemLocator, 0,
> CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&locator );*
> *_com_util::CheckError( hres );*
>
> Of course when using operator&() if there is any previous pointer it will
> be destroyed by reset(); as it can be seen from my example.
> Please provide feedback and suggestions. :)
>

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/6716d809-544c-4267-8a98-6d928af5892e%40isocpp.org.

------=_Part_19783_1125167956.1523835750683
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">This has actually come up more times than I initially thou=
ght. There are TONS of companies who have this abstraction internally, and =
also tons of people who write this code externally on their own as well.<br=
><br>So, I put it in library form, consumable in CMake, and also enhanced i=
t so that it is usable with `std::shared_ptr`, `boost::shared_ptr`, and (ho=
pefully) with the upcoming `std::retain_ptr`:<br><br><a href=3D"https://git=
hub.com/ThePhD/ptrptr">https://github.com/ThePhD/ptrptr</a><br><br>Of note =
here is the benchmarks. I plan to actually write a blog post about this, be=
cause it seems there is some performance left on the table when going throu=
gh the typical .release() + .reset() route with a `std::unique_ptr`, which =
makes this more than just &quot;nice&quot; to have in the standard library.=
<br><br>On Wednesday, April 11, 2018 at 6:22:39 PM UTC-4, thesto...@gmail.c=
om wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: =
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">Hell=
o,<div><br></div><div>There are many old APIs that are using double pointer=
 as argument to return an object. Wide usage examples are WinAPI, SDL, etc.=
</div><div>Currently you have to use one more temporary variable to pass it=
 and then assign it to std::unique_ptr.</div><div><br></div><div><div><i>//=
 Some utility header file...</i></div><div><i>struct ComCloser</i></div><di=
v><i>{</i></div><div><i><span style=3D"white-space:pre"> </span>constexpr C=
omCloser() noexcept =3D default;</i></div><div><i><span style=3D"white-spac=
e:pre"> </span>void operator()( IUnknown* comObj ) noexcept</i></div><div><=
i><span style=3D"white-space:pre"> </span>{</i></div><div><i><span style=3D=
"white-space:pre">  </span>comObj-&gt;Release();</i></div><div><i><span sty=
le=3D"white-space:pre"> </span>}</i></div><div><i>};</i></div><div><i><br><=
/i></div><div><i>template&lt;typename T&gt;</i></div><div><i>using ComResou=
rce =3D std::unique_ptr&lt;T, ComCloser&gt;;</i></div><div><i><br></i></div=
><div><i>// Some cpp file</i></div><div><i>IWbemLocator* pLoc =3D nullptr;<=
/i></div><div><i>HRESULT hres =3D CoCreateInstance( CLSID_WbemLocator, 0, C=
LSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&amp;pLoc );</i></div><div>=
<i>_com_util::CheckError( hres ); // will throw exception on error</i></div=
><div><i><br></i></div><div><i>ComResource&lt;IWbemLocator&gt; locator( pLo=
c );</i></div></div><div><br></div><div>By adding</div><div><div><i>pointer=
* operator&amp;()</i></div><div><i>{</i></div><div><i><span style=3D"white-=
space:pre"> </span>reset();<br></i></div><div><i><span style=3D"white-space=
:pre"> </span>return &amp;_ptr;</i></div><div><i>}</i></div></div><div><br>=
</div><div>We can omit most of the cpp file code to become like</div><div><=
div><i>// Some cpp file</i></div><div><i>ComResource&lt;IWbemLocator&gt; lo=
cator;</i></div><div><i>HRESULT hres =3D ::CoCreateInstance( CLSID_WbemLoca=
tor, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&amp;locator );</i=
></div><div><i>_com_util::CheckError( hres );</i></div></div><div><br></div=
><div>Of course when using operator&amp;() if there is any previous pointer=
 it will be destroyed by reset(); as it can be seen from my example.</div><=
div>Please provide feedback and suggestions. :)</div></div></blockquote></d=
iv>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/6716d809-544c-4267-8a98-6d928af5892e%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/6716d809-544c-4267-8a98-6d928af5892e=
%40isocpp.org</a>.<br />

------=_Part_19783_1125167956.1523835750683--

------=_Part_19782_1666191677.1523835750683--

.


Author: The PhD <phdofthehouse@gmail.com>
Date: Sat, 24 Nov 2018 22:45:11 -0800 (PST)
Raw View
------=_Part_932_1017403438.1543128311804
Content-Type: multipart/alternative;
 boundary="----=_Part_933_788707443.1543128311804"

------=_Part_933_788707443.1543128311804
Content-Type: text/plain; charset="UTF-8"

I wanted to follow up to this thread.

I've been busy making sure a form of this suitable for standardization can
make it into C++. It looks like it will make it for C++23, but it can be
put into C++20 if I put enough effort behind it and make it to Kona (which
seems unlikely right now).

Here is the current form of the proposal:
https://thephd.github.io/vendor/future_cxx/papers/d1132.html

It should only need minor tweaks now. Thanks to input from tcanes and
glenfe and pdimov, the wording has been significantly changed to be able to
allow the optimizations discussed in the paper and employed commonly in
source.

A version of this might also be available for the next Boost release cycle,
putting it in user hands faster than my github implementation. It's slated
to slide into Boost.SmartPtr at some point too, provided I can make sure
all the design and wording decisions are solid and aid in the
implementation where necessary.

Thanks for bringing this up!

On Sunday, April 15, 2018 at 7:42:30 PM UTC-4, The PhD wrote:
>
> This has actually come up more times than I initially thought. There are
> TONS of companies who have this abstraction internally, and also tons of
> people who write this code externally on their own as well.
>
> So, I put it in library form, consumable in CMake, and also enhanced it so
> that it is usable with `std::shared_ptr`, `boost::shared_ptr`, and
> (hopefully) with the upcoming `std::retain_ptr`:
>
> https://github.com/ThePhD/ptrptr
>
> Of note here is the benchmarks. I plan to actually write a blog post about
> this, because it seems there is some performance left on the table when
> going through the typical .release() + .reset() route with a
> `std::unique_ptr`, which makes this more than just "nice" to have in the
> standard library.
>
> On Wednesday, April 11, 2018 at 6:22:39 PM UTC-4, thesto...@gmail.com
> wrote:
>>
>> Hello,
>>
>> There are many old APIs that are using double pointer as argument to
>> return an object. Wide usage examples are WinAPI, SDL, etc.
>> Currently you have to use one more temporary variable to pass it and then
>> assign it to std::unique_ptr.
>>
>> *// Some utility header file...*
>> *struct ComCloser*
>> *{*
>> * constexpr ComCloser() noexcept = default;*
>> * void operator()( IUnknown* comObj ) noexcept*
>> * {*
>> * comObj->Release();*
>> * }*
>> *};*
>>
>> *template<typename T>*
>> *using ComResource = std::unique_ptr<T, ComCloser>;*
>>
>> *// Some cpp file*
>> *IWbemLocator* pLoc = nullptr;*
>> *HRESULT hres = CoCreateInstance( CLSID_WbemLocator, 0,
>> CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&pLoc );*
>> *_com_util::CheckError( hres ); // will throw exception on error*
>>
>> *ComResource<IWbemLocator> locator( pLoc );*
>>
>> By adding
>> *pointer* operator&()*
>> *{*
>>
>> * reset();*
>> * return &_ptr;*
>> *}*
>>
>> We can omit most of the cpp file code to become like
>> *// Some cpp file*
>> *ComResource<IWbemLocator> locator;*
>> *HRESULT hres = ::CoCreateInstance( CLSID_WbemLocator, 0,
>> CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&locator );*
>> *_com_util::CheckError( hres );*
>>
>> Of course when using operator&() if there is any previous pointer it will
>> be destroyed by reset(); as it can be seen from my example.
>> Please provide feedback and suggestions. :)
>>
>

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/aa5a4782-b2cf-4339-8d2b-02d08a6f73f9%40isocpp.org.

------=_Part_933_788707443.1543128311804
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>I wanted to follow up to this thread.<br><br>I&#39;ve=
 been busy making sure a form of this suitable for standardization can make=
 it into C++. It looks like it will make it for C++23, but it can be put in=
to C++20 if I put enough effort behind it and make it to Kona (which seems =
unlikely right now).<br><br>Here is the current form of the proposal: <a hr=
ef=3D"https://thephd.github.io/vendor/future_cxx/papers/d1132.html">https:/=
/thephd.github.io/vendor/future_cxx/papers/d1132.html</a><br></div><div><br=
></div><div>It should only need minor tweaks now. Thanks to input from tcan=
es and glenfe and pdimov, the wording has been significantly changed to be =
able to allow the optimizations discussed in the paper and employed commonl=
y in source.<br><br>A version of this might also be available for the next =
Boost release cycle, putting it in user hands faster than my github impleme=
ntation. It&#39;s slated to slide into Boost.SmartPtr at some point too, pr=
ovided I can make sure all the design and wording decisions are solid and a=
id in the implementation where necessary.<br><br>Thanks for bringing this u=
p!<br></div><br>On Sunday, April 15, 2018 at 7:42:30 PM UTC-4, The PhD wrot=
e:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;b=
order-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">This has ac=
tually come up more times than I initially thought. There are TONS of compa=
nies who have this abstraction internally, and also tons of people who writ=
e this code externally on their own as well.<br><br>So, I put it in library=
 form, consumable in CMake, and also enhanced it so that it is usable with =
`std::shared_ptr`, `boost::shared_ptr`, and (hopefully) with the upcoming `=
std::retain_ptr`:<br><br><a href=3D"https://github.com/ThePhD/ptrptr" targe=
t=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;https://www.g=
oogle.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2FThePhD%2Fptrptr\x26sa\x3dD\x2=
6sntz\x3d1\x26usg\x3dAFQjCNHkM7nAOuAjtC8gWaYdbLObIcbJ7w&#39;;return true;" =
onclick=3D"this.href=3D&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fg=
ithub.com%2FThePhD%2Fptrptr\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHkM7nAO=
uAjtC8gWaYdbLObIcbJ7w&#39;;return true;">https://github.com/ThePhD/<wbr>ptr=
ptr</a><br><br>Of note here is the benchmarks. I plan to actually write a b=
log post about this, because it seems there is some performance left on the=
 table when going through the typical .release() + .reset() route with a `s=
td::unique_ptr`, which makes this more than just &quot;nice&quot; to have i=
n the standard library.<br><br>On Wednesday, April 11, 2018 at 6:22:39 PM U=
TC-4, <a>thesto...@gmail.com</a> wrote:<blockquote class=3D"gmail_quote" st=
yle=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1=
ex"><div dir=3D"ltr">Hello,<div><br></div><div>There are many old APIs that=
 are using double pointer as argument to return an object. Wide usage examp=
les are WinAPI, SDL, etc.</div><div>Currently you have to use one more temp=
orary variable to pass it and then assign it to std::unique_ptr.</div><div>=
<br></div><div><div><i>// Some utility header file...</i></div><div><i>stru=
ct ComCloser</i></div><div><i>{</i></div><div><i><span style=3D"white-space=
:pre"> </span>constexpr ComCloser() noexcept =3D default;</i></div><div><i>=
<span style=3D"white-space:pre"> </span>void operator()( IUnknown* comObj )=
 noexcept</i></div><div><i><span style=3D"white-space:pre"> </span>{</i></d=
iv><div><i><span style=3D"white-space:pre">  </span>comObj-&gt;Release();</=
i></div><div><i><span style=3D"white-space:pre"> </span>}</i></div><div><i>=
};</i></div><div><i><br></i></div><div><i>template&lt;typename T&gt;</i></d=
iv><div><i>using ComResource =3D std::unique_ptr&lt;T, ComCloser&gt;;</i></=
div><div><i><br></i></div><div><i>// Some cpp file</i></div><div><i>IWbemLo=
cator* pLoc =3D nullptr;</i></div><div><i>HRESULT hres =3D CoCreateInstance=
( CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&a=
mp;pLoc );</i></div><div><i>_com_util::CheckError( hres ); // will throw ex=
ception on error</i></div><div><i><br></i></div><div><i>ComResource&lt;IWbe=
mLocator&gt; locator( pLoc );</i></div></div><div><br></div><div>By adding<=
/div><div><div><i>pointer* operator&amp;()</i></div><div><i>{</i></div><div=
><i><span style=3D"white-space:pre"> </span>reset();<br></i></div><div><i><=
span style=3D"white-space:pre"> </span>return &amp;_ptr;</i></div><div><i>}=
</i></div></div><div><br></div><div>We can omit most of the cpp file code t=
o become like</div><div><div><i>// Some cpp file</i></div><div><i>ComResour=
ce&lt;IWbemLocator&gt; locator;</i></div><div><i>HRESULT hres =3D ::CoCreat=
eInstance( CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (L=
PVOID*)&amp;locator );</i></div><div><i>_com_util::CheckError( hres );</i><=
/div></div><div><br></div><div>Of course when using operator&amp;() if ther=
e is any previous pointer it will be destroyed by reset(); as it can be see=
n from my example.</div><div>Please provide feedback and suggestions. :)</d=
iv></div></blockquote></div></blockquote></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/aa5a4782-b2cf-4339-8d2b-02d08a6f73f9%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/aa5a4782-b2cf-4339-8d2b-02d08a6f73f9=
%40isocpp.org</a>.<br />

------=_Part_933_788707443.1543128311804--

------=_Part_932_1017403438.1543128311804--

.


Author: The Storm <thestorm.nik@gmail.com>
Date: Sun, 25 Nov 2018 11:34:59 +0200
Raw View
--000000000000db2a94057b79ee34
Content-Type: text/plain; charset="UTF-8"

Very nice! I've been losing hope in ever seeing the final missing piece for
pointers.

Wish you best of luck in getting this accepted as soon as possible!

On Sun, Nov 25, 2018, 08:45 The PhD <phdofthehouse@gmail.com wrote:

> I wanted to follow up to this thread.
>
> I've been busy making sure a form of this suitable for standardization can
> make it into C++. It looks like it will make it for C++23, but it can be
> put into C++20 if I put enough effort behind it and make it to Kona (which
> seems unlikely right now).
>
> Here is the current form of the proposal:
> https://thephd.github.io/vendor/future_cxx/papers/d1132.html
>
> It should only need minor tweaks now. Thanks to input from tcanes and
> glenfe and pdimov, the wording has been significantly changed to be able to
> allow the optimizations discussed in the paper and employed commonly in
> source.
>
> A version of this might also be available for the next Boost release
> cycle, putting it in user hands faster than my github implementation. It's
> slated to slide into Boost.SmartPtr at some point too, provided I can make
> sure all the design and wording decisions are solid and aid in the
> implementation where necessary.
>
> Thanks for bringing this up!
>
> On Sunday, April 15, 2018 at 7:42:30 PM UTC-4, The PhD wrote:
>>
>> This has actually come up more times than I initially thought. There are
>> TONS of companies who have this abstraction internally, and also tons of
>> people who write this code externally on their own as well.
>>
>> So, I put it in library form, consumable in CMake, and also enhanced it
>> so that it is usable with `std::shared_ptr`, `boost::shared_ptr`, and
>> (hopefully) with the upcoming `std::retain_ptr`:
>>
>> https://github.com/ThePhD/ptrptr
>>
>> Of note here is the benchmarks. I plan to actually write a blog post
>> about this, because it seems there is some performance left on the table
>> when going through the typical .release() + .reset() route with a
>> `std::unique_ptr`, which makes this more than just "nice" to have in the
>> standard library.
>>
>> On Wednesday, April 11, 2018 at 6:22:39 PM UTC-4, thesto...@gmail.com
>> wrote:
>>>
>>> Hello,
>>>
>>> There are many old APIs that are using double pointer as argument to
>>> return an object. Wide usage examples are WinAPI, SDL, etc.
>>> Currently you have to use one more temporary variable to pass it and
>>> then assign it to std::unique_ptr.
>>>
>>> *// Some utility header file...*
>>> *struct ComCloser*
>>> *{*
>>> * constexpr ComCloser() noexcept = default;*
>>> * void operator()( IUnknown* comObj ) noexcept*
>>> * {*
>>> * comObj->Release();*
>>> * }*
>>> *};*
>>>
>>> *template<typename T>*
>>> *using ComResource = std::unique_ptr<T, ComCloser>;*
>>>
>>> *// Some cpp file*
>>> *IWbemLocator* pLoc = nullptr;*
>>> *HRESULT hres = CoCreateInstance( CLSID_WbemLocator, 0,
>>> CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&pLoc );*
>>> *_com_util::CheckError( hres ); // will throw exception on error*
>>>
>>> *ComResource<IWbemLocator> locator( pLoc );*
>>>
>>> By adding
>>> *pointer* operator&()*
>>> *{*
>>>
>>> * reset();*
>>> * return &_ptr;*
>>> *}*
>>>
>>> We can omit most of the cpp file code to become like
>>> *// Some cpp file*
>>> *ComResource<IWbemLocator> locator;*
>>> *HRESULT hres = ::CoCreateInstance( CLSID_WbemLocator, 0,
>>> CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&locator );*
>>> *_com_util::CheckError( hres );*
>>>
>>> Of course when using operator&() if there is any previous pointer it
>>> will be destroyed by reset(); as it can be seen from my example.
>>> Please provide feedback and suggestions. :)
>>>
>>

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAGtQ8bhGM2uz3XKF8nX1Cr-fo9k_k8fuMBZL89MPgUR%3Ds0XSVw%40mail.gmail.com.

--000000000000db2a94057b79ee34
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"auto">Very nice! I&#39;ve been losing hope in ever seeing the f=
inal missing piece for pointers.<div dir=3D"auto"><br></div><div dir=3D"aut=
o">Wish you best of luck in getting this accepted as soon as possible!</div=
></div><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Sun, Nov 25, 2018=
, 08:45 The PhD &lt;<a href=3D"mailto:phdofthehouse@gmail.com">phdofthehous=
e@gmail.com</a> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"=
margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"=
ltr"><div>I wanted to follow up to this thread.<br><br>I&#39;ve been busy m=
aking sure a form of this suitable for standardization can make it into C++=
.. It looks like it will make it for C++23, but it can be put into C++20 if =
I put enough effort behind it and make it to Kona (which seems unlikely rig=
ht now).<br><br>Here is the current form of the proposal: <a href=3D"https:=
//thephd.github.io/vendor/future_cxx/papers/d1132.html" target=3D"_blank" r=
el=3D"noreferrer">https://thephd.github.io/vendor/future_cxx/papers/d1132.h=
tml</a><br></div><div><br></div><div>It should only need minor tweaks now. =
Thanks to input from tcanes and glenfe and pdimov, the wording has been sig=
nificantly changed to be able to allow the optimizations discussed in the p=
aper and employed commonly in source.<br><br>A version of this might also b=
e available for the next Boost release cycle, putting it in user hands fast=
er than my github implementation. It&#39;s slated to slide into Boost.Smart=
Ptr at some point too, provided I can make sure all the design and wording =
decisions are solid and aid in the implementation where necessary.<br><br>T=
hanks for bringing this up!<br></div><br>On Sunday, April 15, 2018 at 7:42:=
30 PM UTC-4, The PhD wrote:<blockquote class=3D"gmail_quote" style=3D"margi=
n:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=
=3D"ltr">This has actually come up more times than I initially thought. The=
re are TONS of companies who have this abstraction internally, and also ton=
s of people who write this code externally on their own as well.<br><br>So,=
 I put it in library form, consumable in CMake, and also enhanced it so tha=
t it is usable with `std::shared_ptr`, `boost::shared_ptr`, and (hopefully)=
 with the upcoming `std::retain_ptr`:<br><br><a href=3D"https://github.com/=
ThePhD/ptrptr" rel=3D"nofollow noreferrer" target=3D"_blank">https://github=
..com/ThePhD/ptrptr</a><br><br>Of note here is the benchmarks. I plan to act=
ually write a blog post about this, because it seems there is some performa=
nce left on the table when going through the typical .release() + .reset() =
route with a `std::unique_ptr`, which makes this more than just &quot;nice&=
quot; to have in the standard library.<br><br>On Wednesday, April 11, 2018 =
at 6:22:39 PM UTC-4, <a rel=3D"noreferrer">thesto...@gmail.com</a> wrote:<b=
lockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-=
left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Hello,<div><br></div=
><div>There are many old APIs that are using double pointer as argument to =
return an object. Wide usage examples are WinAPI, SDL, etc.</div><div>Curre=
ntly you have to use one more temporary variable to pass it and then assign=
 it to std::unique_ptr.</div><div><br></div><div><div><i>// Some utility he=
ader file...</i></div><div><i>struct ComCloser</i></div><div><i>{</i></div>=
<div><i><span style=3D"white-space:pre-wrap"> </span>constexpr ComCloser() =
noexcept =3D default;</i></div><div><i><span style=3D"white-space:pre-wrap"=
> </span>void operator()( IUnknown* comObj ) noexcept</i></div><div><i><spa=
n style=3D"white-space:pre-wrap"> </span>{</i></div><div><i><span style=3D"=
white-space:pre-wrap">  </span>comObj-&gt;Release();</i></div><div><i><span=
 style=3D"white-space:pre-wrap"> </span>}</i></div><div><i>};</i></div><div=
><i><br></i></div><div><i>template&lt;typename T&gt;</i></div><div><i>using=
 ComResource =3D std::unique_ptr&lt;T, ComCloser&gt;;</i></div><div><i><br>=
</i></div><div><i>// Some cpp file</i></div><div><i>IWbemLocator* pLoc =3D =
nullptr;</i></div><div><i>HRESULT hres =3D CoCreateInstance( CLSID_WbemLoca=
tor, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&amp;pLoc );</i></=
div><div><i>_com_util::CheckError( hres ); // will throw exception on error=
</i></div><div><i><br></i></div><div><i>ComResource&lt;IWbemLocator&gt; loc=
ator( pLoc );</i></div></div><div><br></div><div>By adding</div><div><div><=
i>pointer* operator&amp;()</i></div><div><i>{</i></div><div><i><span style=
=3D"white-space:pre-wrap"> </span>reset();<br></i></div><div><i><span style=
=3D"white-space:pre-wrap"> </span>return &amp;_ptr;</i></div><div><i>}</i><=
/div></div><div><br></div><div>We can omit most of the cpp file code to bec=
ome like</div><div><div><i>// Some cpp file</i></div><div><i>ComResource&lt=
;IWbemLocator&gt; locator;</i></div><div><i>HRESULT hres =3D ::CoCreateInst=
ance( CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID=
*)&amp;locator );</i></div><div><i>_com_util::CheckError( hres );</i></div>=
</div><div><br></div><div>Of course when using operator&amp;() if there is =
any previous pointer it will be destroyed by reset(); as it can be seen fro=
m my example.</div><div>Please provide feedback and suggestions. :)</div></=
div></blockquote></div></blockquote></div></blockquote></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAGtQ8bhGM2uz3XKF8nX1Cr-fo9k_k8fuMBZL=
89MPgUR%3Ds0XSVw%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAGtQ8bhGM2uz3X=
KF8nX1Cr-fo9k_k8fuMBZL89MPgUR%3Ds0XSVw%40mail.gmail.com</a>.<br />

--000000000000db2a94057b79ee34--

.


Author: Balog Pal <pasa@lib.hu>
Date: Sun, 25 Nov 2018 14:56:38 -0800 (PST)
Raw View
------=_Part_965_755099550.1543186598091
Content-Type: multipart/alternative;
 boundary="----=_Part_966_1197243978.1543186598092"

------=_Part_966_1197243978.1543186598092
Content-Type: text/plain; charset="UTF-8"

Using & for that purpose is an awful idea.  Even if this class was newly
introduced so it would not just break/redirect user code that already uses
& and cant to get the address of the unique_ptr instance.

OTOH the feature you are looking for is legit. My own suite of smart
pointers have a named function that returns Ptr& to the internals -- marked
with ton of warnings to not use it unless one really knows the way.  For
cases similar to that. I'm pretty sure that function, that way would have
snawball's chance in hell to get standardized.

If all you look after is to deal with COM objects, ATL and MFC has great
simple support.

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/f90723cd-dee4-48c0-95ee-32699861b393%40isocpp.org.

------=_Part_966_1197243978.1543186598092
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Using &amp; for that purpose is an awful idea.=C2=A0 =
Even if this class was newly introduced so it would not just break/redirect=
 user code that already uses &amp; and cant to get the address of the uniqu=
e_ptr instance.</div><div><br></div><div>OTOH the feature you are looking f=
or is legit. My own suite of smart pointers have a named function that retu=
rns Ptr&amp; to the internals -- marked with ton of warnings to not use it =
unless one really knows the way.=C2=A0 For cases similar to that. I&#39;m p=
retty sure that function, that way would have snawball&#39;s chance in hell=
 to get standardized.=C2=A0=C2=A0 <br></div><div><br></div><div>If all you =
look after is to deal with COM objects, ATL and MFC has great simple suppor=
t. <br></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/f90723cd-dee4-48c0-95ee-32699861b393%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/f90723cd-dee4-48c0-95ee-32699861b393=
%40isocpp.org</a>.<br />

------=_Part_966_1197243978.1543186598092--

------=_Part_965_755099550.1543186598091--

.


Author: Alberto Barbati <albertobarbati@gmail.com>
Date: Tue, 27 Nov 2018 08:10:29 -0800 (PST)
Raw View
------=_Part_1768_259041496.1543335029436
Content-Type: multipart/alternative;
 boundary="----=_Part_1769_1090983729.1543335029436"

------=_Part_1769_1090983729.1543335029436
Content-Type: text/plain; charset="UTF-8"

Il giorno domenica 25 novembre 2018 23:56:38 UTC+1, Balog Pal ha scritto:
>
> Using & for that purpose is an awful idea.  Even if this class was newly
> introduced so it would not just break/redirect user code that already uses
> & and cant to get the address of the unique_ptr instance.
>
> OTOH the feature you are looking for is legit. My own suite of smart
> pointers have a named function that returns Ptr& to the internals -- marked
> with ton of warnings to not use it unless one really knows the way.  For
> cases similar to that. I'm pretty sure that function, that way would have
> snawball's chance in hell to get standardized.
>
> If all you look after is to deal with COM objects, ATL and MFC has great
> simple support.
>

If you had read paper P1132R2 you would have noticed that it does *not*
propose to overload operator&. It solves the problem by introducing a
couple new classes without changing unique_ptr or any other existing smart
pointer class. The approach is neat, it doesn't require "ton of warnings",
potentially works with every smart pointer and, being a pure library
extension, cannot break existing code. Although I do not currently have the
need for it, I hope it gets the attention it deserves.

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/cfb3ee24-a385-45d0-8284-fa1ec918fcb0%40isocpp.org.

------=_Part_1769_1090983729.1543335029436
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Il giorno domenica 25 novembre 2018 23:56:38 UTC+1, Balog =
Pal ha scritto:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-=
left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr=
"><div>Using &amp; for that purpose is an awful idea.=C2=A0 Even if this cl=
ass was newly introduced so it would not just break/redirect user code that=
 already uses &amp; and cant to get the address of the unique_ptr instance.=
</div><div><br></div><div>OTOH the feature you are looking for is legit. My=
 own suite of smart pointers have a named function that returns Ptr&amp; to=
 the internals -- marked with ton of warnings to not use it unless one real=
ly knows the way.=C2=A0 For cases similar to that. I&#39;m pretty sure that=
 function, that way would have snawball&#39;s chance in hell to get standar=
dized.=C2=A0=C2=A0 <br></div><div><br></div><div>If all you look after is t=
o deal with COM objects, ATL and MFC has great simple support. <br></div></=
div></blockquote><div><br></div><div>If you had read paper P1132R2 you woul=
d have noticed that it does <b>not</b> propose to overload operator&amp;. I=
t solves the problem by introducing a couple new classes without changing u=
nique_ptr or any other existing smart pointer class. The approach is neat, =
it doesn&#39;t require &quot;ton of warnings&quot;, potentially works with =
every smart pointer and, being a pure library extension, cannot break exist=
ing code. Although I do not currently have the need for it, I hope it gets =
the attention it deserves.</div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/cfb3ee24-a385-45d0-8284-fa1ec918fcb0%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/cfb3ee24-a385-45d0-8284-fa1ec918fcb0=
%40isocpp.org</a>.<br />

------=_Part_1769_1090983729.1543335029436--

------=_Part_1768_259041496.1543335029436--

.