Topic: Can we allow the adopt_lock_t argument to
Author: Brian Bi <bbi5291@gmail.com>
Date: Thu, 16 Feb 2017 02:09:01 -0800
Raw View
--001a114627227ecf780548a2fce6
Content-Type: text/plain; charset=UTF-8
Having it at the end:
template <class... MutexTypes>
class lock_guard {
public:
using mutex_type = Mutex; // If MutexTypes... consists of the
single type Mutex
explicit lock_guard(MutexTypes&... m);
lock_guard(MutexTypes&... m, adopt_lock_t); // ... };
is inconvenient for class template argument deduction. Namely, it is
impossible to deduce the adopt_lock_t constructor from a declaration;
instead, the last type in MutexTypes will be deduced to adopt_lock_t and a
compilation error will occur.
What if we added a new constructor that would allow putting it at the
beginning?
lock_guard(adopt_lock_t, MutexTypes&... m);
- Old code (C++11 and C++14) wouldn't break because in those cases
MutexTypes would have size 1 and the template argument would be explicitly
specified.
- Empty MutexTypes would cause a compilation error, but that can be
avoided by simply adding language saying that this constructor is not
defined when sizeof...(MutexTypes) is 0.
- Deduction appears to work as one would want:
http://melpon.org/wandbox/permlink/VQjKh7ugZzZnoBqx
Any problems with this idea?
--
*Brian Bi*
--
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/CAMmfjbP%2BRNv5VGY-96NV7HkXt2%3D25n_ZDKWu%3DxJdxfbPHKrosg%40mail.gmail.com.
--001a114627227ecf780548a2fce6
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div><div>Having it at the end:<br>
<pre class=3D"gmail-codeblock"> template <class... MutexTypes>
class lock_guard {
public:
using mutex_type =3D Mutex; <span class=3D"gmail-comment">// If <span =
class=3D"gmail-tcode_in_codeblock">MutexTypes...</span> consists of the sin=
gle type <span class=3D"gmail-tcode_in_codeblock">Mutex</span>
</span>
explicit lock_guard(MutexTypes&... m);
lock_guard(MutexTypes&... m, adopt_lock_t);
<span class=3D"gmail-comment"><span class=3D"gmail-textit"> // ...</span=
>
</span> };</pre></div>is inconvenient for class template argument deductio=
n. Namely, it is impossible to deduce the adopt_lock_t constructor from a d=
eclaration; instead, the last type in MutexTypes will be deduced to adopt_l=
ock_t and a compilation error will occur.<br><br></div>What if we added a n=
ew constructor that would allow putting it at the beginning?<br><pre class=
=3D"gmail-codeblock"> lock_guard(adopt_lock_t, MutexTypes&... m);</p=
re><ul><li>Old code (C++11 and C++14) wouldn't break because in those c=
ases MutexTypes would have size 1 and the template argument would be explic=
itly specified.</li><li>Empty MutexTypes would cause a compilation error, b=
ut that can be avoided by simply adding language saying that this construct=
or is not defined when sizeof...(MutexTypes) is 0.</li><li>Deduction appear=
s to work as one would want: <a href=3D"http://melpon.org/wandbox/permlink/=
VQjKh7ugZzZnoBqx">http://melpon.org/wandbox/permlink/VQjKh7ugZzZnoBqx</a></=
li></ul><p>Any problems with this idea?<br></p><br><br clear=3D"all"><div><=
div><div><div><div><br>-- <br><div class=3D"gmail_signature"><div dir=3D"lt=
r"><div><div dir=3D"ltr"><font color=3D"#c0c0c0"><i>Brian Bi</i></font><br>=
<div></div><div></div><div></div></div></div></div></div>
</div></div></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" 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/CAMmfjbP%2BRNv5VGY-96NV7HkXt2%3D25n_Z=
DKWu%3DxJdxfbPHKrosg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfoote=
r">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAMmfjbP%2B=
RNv5VGY-96NV7HkXt2%3D25n_ZDKWu%3DxJdxfbPHKrosg%40mail.gmail.com</a>.<br />
--001a114627227ecf780548a2fce6--
.