Topic: Concepts requires clause should allow types that
Author: toby.brull@gmail.com
Date: Sat, 14 Jul 2018 17:31:00 -0700 (PDT)
Raw View
------=_Part_134683_1546255666.1531614660505
Content-Type: multipart/alternative;
boundary="----=_Part_134684_1833482427.1531614660506"
------=_Part_134684_1833482427.1531614660506
Content-Type: text/plain; charset="UTF-8"
Apologies, if this is off-topic.
It seems that the following doesn't compile in all versions of gcc that I
tried (7.2, 8.1, 9.0). It complains that the type of the value in the
"requires" clause is not bool, although the value is implicitly constexpr
convertible to bool.
template<typename T, T v>
constexpr auto is_even (std::integral_constant<T, v> = {})
{
return std::bool_constant<(v % 2 == 0)> {};
}
template<typename T, T v>
requires is_even (std::integral_constant<T, v> {}) // (*)
int some_function ()
{
return (v * 3);
}
int main ()
{
std::cout << some_function<int, 4> () << '\n';
}
Workarounds are, of course, to append "()" or to prepend "!!" to the line
marked with (*), but might be better without? If this is not a bug in gcc,
I hoped someone would be able to make that change easily at this point.
--
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/79029827-71df-4af1-ae50-607e96c5e322%40isocpp.org.
------=_Part_134684_1833482427.1531614660506
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>Apologies, if this is off-topic.</div><div><br></div>=
<div>It seems that the following doesn't compile in all versions of gcc=
that I tried (7.2, 8.1, 9.0). It complains that the type of the value in t=
he "requires" clause is not bool, although the value is implicitl=
y constexpr convertible to bool.</div><div><br></div><div><br></div><blockq=
uote style=3D"margin: 0 0 0 40px; border: none; padding: 0px;"><div><font f=
ace=3D"courier new, monospace">template<typename T, T v></font></div>=
<div><font face=3D"courier new, monospace">constexpr auto is_even (std::int=
egral_constant<T, v> =3D {})</font></div><div><font face=3D"courier n=
ew, monospace">{</font></div><div><font face=3D"courier new, monospace">=C2=
=A0 return std::bool_constant<(v % 2 =3D=3D 0)> {};</font></div><div>=
<font face=3D"courier new, monospace">}</font></div><div><font face=3D"cour=
ier new, monospace"><br></font></div><div><font face=3D"courier new, monosp=
ace">template<typename T, T v></font></div><div><font face=3D"courier=
new, monospace">=C2=A0 requires is_even (std::integral_constant<T, v>=
; {})=C2=A0 // (*)</font></div><div><font face=3D"courier new, monospace">i=
nt some_function ()</font></div><div><font face=3D"courier new, monospace">=
{</font></div><div><font face=3D"courier new, monospace">=C2=A0 return (v *=
3);</font></div><div><font face=3D"courier new, monospace">}</font></div><=
div><font face=3D"courier new, monospace"><br></font></div><div><font face=
=3D"courier new, monospace">int main ()</font></div><div><font face=3D"cour=
ier new, monospace">{</font></div><div><font face=3D"courier new, monospace=
">=C2=A0 std::cout << some_function<int, 4> () << '\n=
';</font></div><div><font face=3D"courier new, monospace">}</font></div=
></blockquote><div><br></div><div>Workarounds are, of course, to append &qu=
ot;()" or to prepend "!!" to the line marked with (*), but m=
ight be better without? If this is not a bug in gcc, I hoped someone would =
be able to make that change easily at this point.</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/79029827-71df-4af1-ae50-607e96c5e322%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/79029827-71df-4af1-ae50-607e96c5e322=
%40isocpp.org</a>.<br />
------=_Part_134684_1833482427.1531614660506--
------=_Part_134683_1546255666.1531614660505--
.
Author: Nicolas Lesser <blitzrakete@gmail.com>
Date: Sun, 15 Jul 2018 11:38:30 +0200
Raw View
--0000000000007b6afa0571067af8
Content-Type: text/plain; charset="UTF-8"
Yes, this is intended. See [temp.constr.atomic]p3.
And I agree that any type implicitly convertible to bool should be allowed.
On Sun, Jul 15, 2018, 2:31 AM <toby.brull@gmail.com> wrote:
> Apologies, if this is off-topic.
>
> It seems that the following doesn't compile in all versions of gcc that I
> tried (7.2, 8.1, 9.0). It complains that the type of the value in the
> "requires" clause is not bool, although the value is implicitly constexpr
> convertible to bool.
>
>
> template<typename T, T v>
> constexpr auto is_even (std::integral_constant<T, v> = {})
> {
> return std::bool_constant<(v % 2 == 0)> {};
> }
>
> template<typename T, T v>
> requires is_even (std::integral_constant<T, v> {}) // (*)
> int some_function ()
> {
> return (v * 3);
> }
>
> int main ()
> {
> std::cout << some_function<int, 4> () << '\n';
> }
>
>
> Workarounds are, of course, to append "()" or to prepend "!!" to the line
> marked with (*), but might be better without? If this is not a bug in gcc,
> I hoped someone would be able to make that change easily at this point.
>
> --
> 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/79029827-71df-4af1-ae50-607e96c5e322%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/79029827-71df-4af1-ae50-607e96c5e322%40isocpp.org?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/CALmDwq07Aispgz_-pTGix%3D1vGpF1QupHUFgzw9D0bggGQL5_oQ%40mail.gmail.com.
--0000000000007b6afa0571067af8
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"auto"><div>Yes, this is intended. See [temp.constr.atomic]p3.</=
div><div dir=3D"auto"><br></div><div dir=3D"auto">And I agree that any type=
implicitly convertible to bool should be allowed.</div><div dir=3D"auto"><=
br><div class=3D"gmail_quote" dir=3D"auto"><div dir=3D"ltr">On Sun, Jul 15,=
2018, 2:31 AM <<a href=3D"mailto:toby.brull@gmail.com">toby.brull@gmai=
l.com</a>> wrote:<br></div><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>Apologies, if this is off-topic.</div><div><br></div><div>It seems =
that the following doesn't compile in all versions of gcc that I tried =
(7.2, 8.1, 9.0). It complains that the type of the value in the "requi=
res" clause is not bool, although the value is implicitly constexpr co=
nvertible to bool.</div><div><br></div><div><br></div><blockquote style=3D"=
margin:0 0 0 40px;border:none;padding:0px"><div><font face=3D"courier new, =
monospace">template<typename T, T v></font></div><div><font face=3D"c=
ourier new, monospace">constexpr auto is_even (std::integral_constant<T,=
v> =3D {})</font></div><div><font face=3D"courier new, monospace">{</fo=
nt></div><div><font face=3D"courier new, monospace">=C2=A0 return std::bool=
_constant<(v % 2 =3D=3D 0)> {};</font></div><div><font face=3D"courie=
r new, monospace">}</font></div><div><font face=3D"courier new, monospace">=
<br></font></div><div><font face=3D"courier new, monospace">template<typ=
ename T, T v></font></div><div><font face=3D"courier new, monospace">=C2=
=A0 requires is_even (std::integral_constant<T, v> {})=C2=A0 // (*)</=
font></div><div><font face=3D"courier new, monospace">int some_function ()<=
/font></div><div><font face=3D"courier new, monospace">{</font></div><div><=
font face=3D"courier new, monospace">=C2=A0 return (v * 3);</font></div><di=
v><font face=3D"courier new, monospace">}</font></div><div><font face=3D"co=
urier new, monospace"><br></font></div><div><font face=3D"courier new, mono=
space">int main ()</font></div><div><font face=3D"courier new, monospace">{=
</font></div><div><font face=3D"courier new, monospace">=C2=A0 std::cout &l=
t;< some_function<int, 4> () << '\n';</font></div><d=
iv><font face=3D"courier new, monospace">}</font></div></blockquote><div><b=
r></div><div>Workarounds are, of course, to append "()" or to pre=
pend "!!" to the line marked with (*), but might be better withou=
t? If this is not a bug in gcc, I hoped someone would be able to make that =
change easily at this point.</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" 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/79029827-71df-4af1-ae50-607e96c5e322%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank" =
rel=3D"noreferrer">https://groups.google.com/a/isocpp.org/d/msgid/std-propo=
sals/79029827-71df-4af1-ae50-607e96c5e322%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" 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/CALmDwq07Aispgz_-pTGix%3D1vGpF1QupHUF=
gzw9D0bggGQL5_oQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CALmDwq07Aispgz=
_-pTGix%3D1vGpF1QupHUFgzw9D0bggGQL5_oQ%40mail.gmail.com</a>.<br />
--0000000000007b6afa0571067af8--
.
Author: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
Date: Sun, 15 Jul 2018 15:44:52 -0700 (PDT)
Raw View
------=_Part_159664_1388953426.1531694692616
Content-Type: multipart/alternative;
boundary="----=_Part_159665_1521112249.1531694692616"
------=_Part_159665_1521112249.1531694692616
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Another easy workaround would be to change the word `auto` to `bool`.
I would expect requires(x) to follow exactly the same rules as noexcept(x).=
=20
If it doesn't, that's a bug in my book.
=E2=80=93Arthur
On Sunday, July 15, 2018 at 2:38:44 AM UTC-7, Nicolas Lesser wrote:
>
> Yes, this is intended. See [temp.constr.atomic]p3.
>
> And I agree that any type implicitly convertible to bool should be allowe=
d.
>
> On Sun, Jul 15, 2018, 2:31 AM <toby....@gmail.com <javascript:>> wrote:
>
>> Apologies, if this is off-topic.
>>
>> It seems that the following doesn't compile in all versions of gcc that =
I=20
>> tried (7.2, 8.1, 9.0). It complains that the type of the value in the=20
>> "requires" clause is not bool, although the value is implicitly constexp=
r=20
>> convertible to bool.
>>
>>
>> template<typename T, T v>
>> constexpr auto is_even (std::integral_constant<T, v> =3D {})
>> {
>> return std::bool_constant<(v % 2 =3D=3D 0)> {};
>> }
>>
>> template<typename T, T v>
>> requires is_even (std::integral_constant<T, v> {}) // (*)
>> int some_function ()
>> {
>> return (v * 3);
>> }
>>
>> int main ()
>> {
>> std::cout << some_function<int, 4> () << '\n';
>> }
>>
>>
>> Workarounds are, of course, to append "()" or to prepend "!!" to the lin=
e=20
>> marked with (*), but might be better without? If this is not a bug in gc=
c,=20
>> I hoped someone would be able to make that change easily at this point.
>>
>> --=20
>> You received this message because you are subscribed to the Google Group=
s=20
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n=20
>> email to std-proposal...@isocpp.org <javascript:>.
>> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
>> To view this discussion on the web visit=20
>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/79029827-71=
df-4af1-ae50-607e96c5e322%40isocpp.org=20
>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/79029827-7=
1df-4af1-ae50-607e96c5e322%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoo=
ter>
>> .
>>
>
--=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/0f77fb8d-5058-47e9-b1ec-519958786893%40isocpp.or=
g.
------=_Part_159665_1521112249.1531694692616
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Another easy workaround would be to change the word `auto`=
to `bool`.<div>I would expect requires(x) to follow exactly the same rules=
as noexcept(x). If it doesn't, that's a bug in my book.</div><div>=
<br></div><div>=E2=80=93Arthur<br><br>On Sunday, July 15, 2018 at 2:38:44 A=
M UTC-7, Nicolas Lesser wrote:<blockquote class=3D"gmail_quote" style=3D"ma=
rgin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">=
<div dir=3D"auto"><div>Yes, this is intended. See [temp.constr.atomic]p3.</=
div><div dir=3D"auto"><br></div><div dir=3D"auto">And I agree that any type=
implicitly convertible to bool should be allowed.</div><div dir=3D"auto"><=
br><div class=3D"gmail_quote" dir=3D"auto"><div dir=3D"ltr">On Sun, Jul 15,=
2018, 2:31 AM <<a href=3D"javascript:" target=3D"_blank" gdf-obfuscate=
d-mailto=3D"Q1Rr0d7kCQAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'=
javascript:';return true;" onclick=3D"this.href=3D'javascript:'=
;return true;">toby....@gmail.com</a>> wrote:<br></div><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"><div>Apologies, if this is off-topic.</div><=
div><br></div><div>It seems that the following doesn't compile in all v=
ersions of gcc that I tried (7.2, 8.1, 9.0). It complains that the type of =
the value in the "requires" clause is not bool, although the valu=
e is implicitly constexpr convertible to bool.</div><div><br></div><div><br=
></div><blockquote style=3D"margin:0 0 0 40px;border:none;padding:0px"><div=
><font face=3D"courier new, monospace">template<typename T, T v></fon=
t></div><div><font face=3D"courier new, monospace">constexpr auto is_even (=
std::integral_constant<T, v> =3D {})</font></div><div><font face=3D"c=
ourier new, monospace">{</font></div><div><font face=3D"courier new, monosp=
ace">=C2=A0 return std::bool_constant<(v % 2 =3D=3D 0)> {};</font></d=
iv><div><font face=3D"courier new, monospace">}</font></div><div><font face=
=3D"courier new, monospace"><br></font></div><div><font face=3D"courier new=
, monospace">template<typename T, T v></font></div><div><font face=3D=
"courier new, monospace">=C2=A0 requires is_even (std::integral_constant<=
;T, v> {})=C2=A0 // (*)</font></div><div><font face=3D"courier new, mono=
space">int some_function ()</font></div><div><font face=3D"courier new, mon=
ospace">{</font></div><div><font face=3D"courier new, monospace">=C2=A0 ret=
urn (v * 3);</font></div><div><font face=3D"courier new, monospace">}</font=
></div><div><font face=3D"courier new, monospace"><br></font></div><div><fo=
nt face=3D"courier new, monospace">int main ()</font></div><div><font face=
=3D"courier new, monospace">{</font></div><div><font face=3D"courier new, m=
onospace">=C2=A0 std::cout << some_function<int, 4> () <<=
'\n';</font></div><div><font face=3D"courier new, monospace">}</fo=
nt></div></blockquote><div><br></div><div>Workarounds are, of course, to ap=
pend "()" or to prepend "!!" to the line marked with (*=
), but might be better without? If this is not a bug in gcc, I hoped someon=
e would be able to make that change easily at this point.</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"javascript:" rel=3D"nofollow" target=3D"_blank" gdf-obfu=
scated-mailto=3D"Q1Rr0d7kCQAJ" onmousedown=3D"this.href=3D'javascript:&=
#39;;return true;" onclick=3D"this.href=3D'javascript:';return true=
;">std-proposal...@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"javascript:" rel=3D"nofollo=
w" target=3D"_blank" gdf-obfuscated-mailto=3D"Q1Rr0d7kCQAJ" onmousedown=3D"=
this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'=
;javascript:';return true;">std-pr...@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/79029827-71df-4af1-ae50-607e96c5e322%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/79029827-71df-4af1-ae50-607e96c5e322%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/79029827-71df-4af1-ae50-607e96c5e322%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/79029827-71df-4af1-<wbr>ae50-=
607e96c5e322%40isocpp.org</a><wbr>.<br>
</blockquote></div></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" 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/0f77fb8d-5058-47e9-b1ec-519958786893%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/0f77fb8d-5058-47e9-b1ec-519958786893=
%40isocpp.org</a>.<br />
------=_Part_159665_1521112249.1531694692616--
------=_Part_159664_1388953426.1531694692616--
.
Author: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
Date: Sun, 15 Jul 2018 15:48:10 -0700 (PDT)
Raw View
------=_Part_48556_996312867.1531694890424
Content-Type: multipart/alternative;
boundary="----=_Part_48557_902166159.1531694890425"
------=_Part_48557_902166159.1531694890425
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
On Sunday, July 15, 2018 at 3:44:52 PM UTC-7, Arthur O'Dwyer wrote:
>
> Another easy workaround would be to change the word `auto` to `bool`.
> I would expect requires(x) to follow exactly the same rules as=20
> noexcept(x). If it doesn't, that's a bug in my book.
>
And IIUC, your original code is equivalent to
template<auto v>
constexpr bool is_even =3D (v % 2 =3D=3D 0);
template<auto v> requires is_even<v>
int some_function()
{
return (v * 3);
}
int main ()
{
std::cout << some_function<4>() << '\n';
}
is that right? The integral_constant stuff just seems unnecessarily=20
confusing to me.
=E2=80=93Arthur
--=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/abe8f0c5-5a08-4301-b26a-871f4abacdab%40isocpp.or=
g.
------=_Part_48557_902166159.1531694890425
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Sunday, July 15, 2018 at 3:44:52 PM UTC-7, Arthur O'=
;Dwyer wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-le=
ft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">=
Another easy workaround would be to change the word `auto` to `bool`.<div>I=
would expect requires(x) to follow exactly the same rules as noexcept(x). =
If it doesn't, that's a bug in my book.</div></div></blockquote><di=
v><br></div><div>And IIUC, your original code is equivalent to</div><div><b=
r></div><div><div><font face=3D"courier new, monospace">template<auto v&=
gt;</font></div><div><font face=3D"courier new, monospace">constexpr bool i=
s_even =3D (v % 2 =3D=3D 0);</font></div><div><br></div><div><font face=3D"=
courier new, monospace">template<auto v></font><span style=3D"font-fa=
mily: "courier new", monospace;">=C2=A0requires is_even<v><=
/span></div><div><span style=3D"font-family: "courier new", monos=
pace;">int some_function()</span></div><div><span style=3D"font-family: &qu=
ot;courier new", monospace;">{</span></div><div><font face=3D"courier =
new, monospace">=C2=A0 return (v * 3);</font></div><div><font face=3D"couri=
er new, monospace">}</font></div><div><font face=3D"courier new, monospace"=
><br></font></div><div><font face=3D"courier new, monospace">int main ()</f=
ont></div><div><font face=3D"courier new, monospace">{</font></div><div><fo=
nt face=3D"courier new, monospace">=C2=A0 std::cout << some_function&=
lt;4>() << '\n';</font></div><div><font face=3D"courier ne=
w, monospace">}</font></div></div><div><font face=3D"courier new, monospace=
"><br></font></div><div>is that right? The integral_constant stuff just see=
ms unnecessarily confusing to me.</div><div><br></div><div>=E2=80=93Arthur<=
/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/abe8f0c5-5a08-4301-b26a-871f4abacdab%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/abe8f0c5-5a08-4301-b26a-871f4abacdab=
%40isocpp.org</a>.<br />
------=_Part_48557_902166159.1531694890425--
------=_Part_48556_996312867.1531694890424--
.
Author: "T. C." <rs2740@gmail.com>
Date: Mon, 16 Jul 2018 15:50:25 -0700 (PDT)
Raw View
------=_Part_167514_1341363581.1531781425142
Content-Type: multipart/alternative;
boundary="----=_Part_167515_1174510557.1531781425143"
------=_Part_167515_1174510557.1531781425143
Content-Type: text/plain; charset="UTF-8"
The "exactly bool" requirement was introduced during the Skillman concepts
meeting. Permitting implicit conversions opens up a can of worms:
struct C { constexpr operator int() const { return 0; } constexpr explicit
operator bool() const { return true; } };
constexpr bool b1 = C{}, b2(C{});
static_assert(!b1);
static_assert(b2);
template<class>
concept C1 = C{}; // contextual conversion, or implicit conversion?
template<class>
concept C2 = C{} && true; // contextual?
template<class>
requires (C{}) // contextual or implicit?
void f();
template<class>
requires (C{}) && true // contextual?
void g();
template<class>
requires (C{}) // there's an implicit logical AND in the constraint
here - is the conversion contextual or implicit?
void h() requires true;
On Sunday, July 15, 2018 at 5:38:44 AM UTC-4, Nicolas Lesser wrote:
>
> Yes, this is intended. See [temp.constr.atomic]p3.
>
> And I agree that any type implicitly convertible to bool should be allowed.
>
> On Sun, Jul 15, 2018, 2:31 AM <toby....@gmail.com <javascript:>> wrote:
>
>> Apologies, if this is off-topic.
>>
>> It seems that the following doesn't compile in all versions of gcc that I
>> tried (7.2, 8.1, 9.0). It complains that the type of the value in the
>> "requires" clause is not bool, although the value is implicitly constexpr
>> convertible to bool.
>>
>>
>> template<typename T, T v>
>> constexpr auto is_even (std::integral_constant<T, v> = {})
>> {
>> return std::bool_constant<(v % 2 == 0)> {};
>> }
>>
>> template<typename T, T v>
>> requires is_even (std::integral_constant<T, v> {}) // (*)
>> int some_function ()
>> {
>> return (v * 3);
>> }
>>
>> int main ()
>> {
>> std::cout << some_function<int, 4> () << '\n';
>> }
>>
>>
>> Workarounds are, of course, to append "()" or to prepend "!!" to the line
>> marked with (*), but might be better without? If this is not a bug in gcc,
>> I hoped someone would be able to make that change easily at this point.
>>
>> --
>> 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-proposal...@isocpp.org <javascript:>.
>> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
>> To view this discussion on the web visit
>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/79029827-71df-4af1-ae50-607e96c5e322%40isocpp.org
>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/79029827-71df-4af1-ae50-607e96c5e322%40isocpp.org?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/99477e9d-42e6-42f7-87ae-747b70d7e5c8%40isocpp.org.
------=_Part_167515_1174510557.1531781425143
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">The "exactly bool" requirement was introduced du=
ring the Skillman concepts meeting. Permitting implicit conversions opens u=
p a can of worms:<div><br></div><div>struct C { constexpr operator int() co=
nst { return 0; } constexpr explicit operator bool() const { return true; }=
};</div><div><br></div><div>constexpr bool b1 =3D C{}, b2(C{});</div><div>=
static_assert(!b1);</div><div>static_assert(b2);</div><div><br></div><div>t=
emplate<class></div><div>concept C1 =3D C{}; // contextual conversion=
, or implicit conversion?</div><div><br></div><div><div><div>template<cl=
ass></div><div>concept C2 =3D C{} && true; // contextual?</div><=
/div><div><br></div><div>template<class></div><div>=C2=A0 =C2=A0requi=
res (C{}) // contextual or implicit?</div><div>void f();</div><div><br></di=
v><div>template<class><br></div><div><div>=C2=A0 =C2=A0requires (C{})=
&& true // contextual?</div><div>void g();</div></div><div><br></d=
iv><div><div>template<class><br></div><div><div>=C2=A0 =C2=A0requires=
(C{})=C2=A0 // there's an implicit logical AND in the constraint here =
- is the conversion contextual or implicit?</div><div>void h() requires tru=
e;=C2=A0</div></div><div><br></div><div>On Sunday, July 15, 2018 at 5:38:44=
AM UTC-4, Nicolas Lesser 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"auto"><div>Yes, this is intended. See [temp.constr.atomic]p3.=
</div><div dir=3D"auto"><br></div><div dir=3D"auto">And I agree that any ty=
pe implicitly convertible to bool should be allowed.</div><div dir=3D"auto"=
><br><div class=3D"gmail_quote" dir=3D"auto"><div dir=3D"ltr">On Sun, Jul 1=
5, 2018, 2:31 AM <<a href=3D"javascript:" target=3D"_blank" gdf-obfusca=
ted-mailto=3D"Q1Rr0d7kCQAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D=
9;javascript:';return true;" onclick=3D"this.href=3D'javascript:=
9;;return true;">toby....@gmail.com</a>> wrote:<br></div><blockquote cla=
ss=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;pa=
dding-left:1ex"><div dir=3D"ltr"><div>Apologies, if this is off-topic.</div=
><div><br></div><div>It seems that the following doesn't compile in all=
versions of gcc that I tried (7.2, 8.1, 9.0). It complains that the type o=
f the value in the "requires" clause is not bool, although the va=
lue is implicitly constexpr convertible to bool.</div><div><br></div><div><=
br></div><blockquote style=3D"margin:0 0 0 40px;border:none;padding:0px"><d=
iv><font face=3D"courier new, monospace">template<typename T, T v></f=
ont></div><div><font face=3D"courier new, monospace">constexpr auto is_even=
(std::integral_constant<T, v> =3D {})</font></div><div><font face=3D=
"courier new, monospace">{</font></div><div><font face=3D"courier new, mono=
space">=C2=A0 return std::bool_constant<(v % 2 =3D=3D 0)> {};</font><=
/div><div><font face=3D"courier new, monospace">}</font></div><div><font fa=
ce=3D"courier new, monospace"><br></font></div><div><font face=3D"courier n=
ew, monospace">template<typename T, T v></font></div><div><font face=
=3D"courier new, monospace">=C2=A0 requires is_even (std::integral_constant=
<T, v> {})=C2=A0 // (*)</font></div><div><font face=3D"courier new, m=
onospace">int some_function ()</font></div><div><font face=3D"courier new, =
monospace">{</font></div><div><font face=3D"courier new, monospace">=C2=A0 =
return (v * 3);</font></div><div><font face=3D"courier new, monospace">}</f=
ont></div><div><font face=3D"courier new, monospace"><br></font></div><div>=
<font face=3D"courier new, monospace">int main ()</font></div><div><font fa=
ce=3D"courier new, monospace">{</font></div><div><font face=3D"courier new,=
monospace">=C2=A0 std::cout << some_function<int, 4> () <&l=
t; '\n';</font></div><div><font face=3D"courier new, monospace">}</=
font></div></blockquote><div><br></div><div>Workarounds are, of course, to =
append "()" or to prepend "!!" to the line marked with =
(*), but might be better without? If this is not a bug in gcc, I hoped some=
one would be able to make that change easily at this point.</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"javascript:" rel=3D"nofollow" target=3D"_blank" gdf-obfu=
scated-mailto=3D"Q1Rr0d7kCQAJ" onmousedown=3D"this.href=3D'javascript:&=
#39;;return true;" onclick=3D"this.href=3D'javascript:';return true=
;">std-proposal...@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"javascript:" rel=3D"nofollo=
w" target=3D"_blank" gdf-obfuscated-mailto=3D"Q1Rr0d7kCQAJ" onmousedown=3D"=
this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'=
;javascript:';return true;">std-pr...@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/79029827-71df-4af1-ae50-607e96c5e322%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/79029827-71df-4af1-ae50-607e96c5e322%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/79029827-71df-4af1-ae50-607e96c5e322%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/79029827-71df-4af1-<wbr>ae50-=
607e96c5e322%40isocpp.org</a><wbr>.<br><br>
</blockquote></div></div></div>
</blockquote></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/99477e9d-42e6-42f7-87ae-747b70d7e5c8%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/99477e9d-42e6-42f7-87ae-747b70d7e5c8=
%40isocpp.org</a>.<br />
------=_Part_167515_1174510557.1531781425143--
------=_Part_167514_1341363581.1531781425142--
.