Topic: n4189 - Generic Scope Guard and RAII Wrapper


Author: Boris Rasin <rasin.boris@gmail.com>
Date: Sun, 9 Nov 2014 08:54:43 -0800 (PST)
Raw View
------=_Part_2305_656644597.1415552083568
Content-Type: text/plain; charset=UTF-8

I have a couple of minor suggestions for the authors:

Convenient as it may be, having automatic conversion to underlying resource
type is dangerous for a RAII wrapper - it allows to silently break
encapsulation:

auto hFile = std::make_unique_resource_checked(CreateFile(...),
INVALID_HANDLE_VALUE, CloseHandle);

// cast operator makes it seamless to use with other APIs needing a HANDLE
ReadFile(hFile, ...);

// which is not always a good thing
CloseHandle(hFile); // oh-oh

The other thing, I already noted previously: I think std::unique_resource
needs to be explicitly specified in such a way that it would be possible to
redefine std::unique_ptr in terms of std::unique_resource like so:

template <typename Resource, typename Deleter = default_delete<Resource>>
using unique_ptr = unique_resource<Resource*, Deleter>;

--

---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_2305_656644597.1415552083568
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I have a couple of minor suggestions for the authors:<br><=
br>Convenient as it may be, having automatic conversion to underlying resou=
rce type is dangerous for a RAII wrapper - it allows to silently break enca=
psulation:<br><br><span style=3D"color: rgb(111, 168, 220);"><span style=3D=
"color: rgb(0, 0, 255);"><span style=3D"font-family: arial,sans-serif;">aut=
o hFile =3D std::make_unique_resource_checked(CreateFile(...), INVALID_HAND=
LE_VALUE, CloseHandle);<br><br>// cast operator makes it seamless to use wi=
th other APIs needing a HANDLE<br>ReadFile(hFile, ...);<br><br>// which is =
not always a good thing<br>CloseHandle(hFile); // oh-oh</span></span><br></=
span><br>The other thing, I already noted previously: I think std::unique_r=
esource needs to be explicitly specified in such a way that it would be pos=
sible to redefine std::unique_ptr in terms of  std::unique_resource like so=
:<br><br>template &lt;typename Resource, typename Deleter =3D default_delet=
e&lt;Resource&gt;&gt;<br>using unique_ptr =3D unique_resource&lt;Resource*,=
 Deleter&gt;;<br><br></div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_2305_656644597.1415552083568--

.