220 39184 <99477e9d-42e6-42f7-87ae-747b70d7e5c8@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: "T. C." <rs2740@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Concepts requires clause should allow types that
 constexpr implicitly convert to bool?
Date: Mon, 16 Jul 2018 15:50:25 -0700 (PDT)
Lines: 203
Approved: news@gmane.org
Message-ID: <99477e9d-42e6-42f7-87ae-747b70d7e5c8@isocpp.org>
References: <79029827-71df-4af1-ae50-607e96c5e322@isocpp.org>
 <CALmDwq07Aispgz_-pTGix=1vGpF1QupHUFgzw9D0bggGQL5_oQ@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_167514_1341363581.1531781425142"
X-Trace: blaine.gmane.org 1531781300 20831 195.159.176.226 (16 Jul 2018 22:48:20 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Mon, 16 Jul 2018 22:48:20 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCQ43G7NQIIRBMWCWTNAKGQEYMW5LUA@isocpp.org Tue Jul 17 00:48:16 2018
Return-path: <std-proposals+bncBCQ43G7NQIIRBMWCWTNAKGQEYMW5LUA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yw0-f197.google.com ([209.85.161.197])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCQ43G7NQIIRBMWCWTNAKGQEYMW5LUA@isocpp.org>)
	id 1ffCHw-0005J0-9u
	for gclcip-std-proposals@m.gmane.org; Tue, 17 Jul 2018 00:48:16 +0200
Original-Received: by mail-yw0-f197.google.com with SMTP id u1-v6sf37316516ywg.6
        for <gclcip-std-proposals@m.gmane.org>; Mon, 16 Jul 2018 15:50:27 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=e513lPmnWPwm7zeLXJ7Kn3JqoJcLWOSLdr5t8fHeP/0=;
        b=uZC/mimT3NWhmq7JiWDvpAptegQ+gT1A0QKGqqu2f/P0VS3Te8DqRwUjpqprEZ/cwV
         CaJS+dzpODk7CA9HHSr8DhGOMs8bSxF0LR8Npzp4dGcQzD9XQWtQFL60i8lS3zc8z5ln
         KOGxbdIfejhD36XB1tuIN3wnN/XSDo9BidEY066hsIU9T0/ogBoORxjMNAlHeJwtAZHw
         opeXcRWn30YNRVJlNBCfVL2xZrtzGFu86jRTtuSophAj03EFhgF21Jx98tcgHjN7geSJ
         7zlDYDxeQg2QeLMwnkcVCnFB0Wqiy4VvmEGXk5KcURZfaDG9gzXI6s5j0MEHA2IgfZgr
         gZ/g==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=e513lPmnWPwm7zeLXJ7Kn3JqoJcLWOSLdr5t8fHeP/0=;
        b=CyoTLXo/yQqBVU3f5fB3lAmwNib+9VSpZ/CjbjYdISO2QgKYBmXvi9zQCgn+tRZdca
         DWNDWOYzlIHpCtm0ovFhvbMbVfF/FPDx84HAV8t3CJ9LrYBz5HywgiXE1mS0txttUzy1
         L9Lzzgs7ydKX7O63oH8RF8jFpl9wW6WoR3seLrCUG3zU/J8M4es7pZ8M1iEVKJFusuhO
         bzCIUzWtxxIHIXCRVSUYYqKRuQ5NnfIjymQuckUShT37oIGse9cAiZ+Q3oln/h9ffIQS
         JqjN6PJNLM4eJem+cGgECFquCP69fdGRnzQ/ixNGQTYes7bHNspZq8cN57obF7lXcKBu
         akcg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:x-original-sender:reply-to:precedence
         :mailing-list:list-id:x-spam-checked-in-group:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=e513lPmnWPwm7zeLXJ7Kn3JqoJcLWOSLdr5t8fHeP/0=;
        b=PDT0Fz1z3dV827YaCB5aSpHQTdWlRCVdIURkQExU9vWkmxF2S2CEG4YhFEFCAO8dUw
         0usVrYdkMxXhPv6FAxbZdxSuQZwjDQhnSOWyDlCyjEyCJWBWLj/xVn2MOlJ4uppWOJau
         N1+ysweBNN+QTIpATBfnIIlxaYu/pf2TA4wkUAfFba5X5iuIrZSdd++WGHL6CXZAeqDw
         Q2cVuN8s6lt0pqPJPmeKOs2FzGirpo+/p+ZUWd3nmon25wL+I4eEOapamQnBFrI4asJR
         W7/Z1zlSI0hreKjpMAGHDIVRkR3CsD3Vg/I0KHIC0jSG1AR0Q9N45zfkU/ndjuO9gOaj
         z9Kg==
X-Gm-Message-State: AOUpUlEfA9UVCArear03tcF9Wb8iFyFxGcKCsOiuIpgTcujVa5j+8mke
	Gt2QFkiBJmPBYL+3NI6OPiIF0Q==
X-Google-Smtp-Source: AAOMgpc0Zh9LavLBOPOkr8vpXu18VkMavwNxtsd+1wqZTuW67grSTCEYLI+c0M2Y2gObMBH7woWG1Q==
X-Received: by 2002:a25:9d92:: with SMTP id v18-v6mr5743545ybp.31.1531781427031;
        Mon, 16 Jul 2018 15:50:27 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 2002:a81:9482:: with SMTP id l124-v6ls4297503ywg.20.gmail; Mon,
 16 Jul 2018 15:50:25 -0700 (PDT)
X-Received: by 2002:a81:7dd6:: with SMTP id y205-v6mr2214009ywc.1.1531781425693;
        Mon, 16 Jul 2018 15:50:25 -0700 (PDT)
In-Reply-To: <CALmDwq07Aispgz_-pTGix=1vGpF1QupHUFgzw9D0bggGQL5_oQ@mail.gmail.com>
X-Original-Sender: rs2740@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:39184
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/39184>

------=_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 &quot;exactly bool&quot; 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&lt;class&gt;</div><div>concept C1 =3D C{}; // contextual conversion=
, or implicit conversion?</div><div><br></div><div><div><div>template&lt;cl=
ass&gt;</div><div>concept C2 =3D C{} &amp;&amp; true; // contextual?</div><=
/div><div><br></div><div>template&lt;class&gt;</div><div>=C2=A0 =C2=A0requi=
res (C{}) // contextual or implicit?</div><div>void f();</div><div><br></di=
v><div>template&lt;class&gt;<br></div><div><div>=C2=A0 =C2=A0requires (C{})=
 &amp;&amp; true // contextual?</div><div>void g();</div></div><div><br></d=
iv><div><div>template&lt;class&gt;<br></div><div><div>=C2=A0 =C2=A0requires=
 (C{})=C2=A0 // there&#39;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  &lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfusca=
ted-mailto=3D"Q1Rr0d7kCQAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#3=
9;javascript:&#39;;return true;" onclick=3D"this.href=3D&#39;javascript:&#3=
9;;return true;">toby....@gmail.com</a>&gt; 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&#39;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 &quot;requires&quot; 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&lt;typename T, T v&gt;</f=
ont></div><div><font face=3D"courier new, monospace">constexpr auto is_even=
 (std::integral_constant&lt;T, v&gt; =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&lt;(v % 2 =3D=3D 0)&gt; {};</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&lt;typename T, T v&gt;</font></div><div><font face=
=3D"courier new, monospace">=C2=A0 requires is_even (std::integral_constant=
&lt;T, v&gt; {})=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 &lt;&lt; some_function&lt;int, 4&gt; () &lt;&l=
t; &#39;\n&#39;;</font></div><div><font face=3D"courier new, monospace">}</=
font></div></blockquote><div><br></div><div>Workarounds are, of course, to =
append &quot;()&quot; or to prepend &quot;!!&quot; 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&quot; 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&#39;javascript:&=
#39;;return true;" onclick=3D"this.href=3D&#39;javascript:&#39;;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&#39;javascript:&#39;;return true;" onclick=3D"this.href=3D&#39=
;javascript:&#39;;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&amp;utm_source=3Dfooter" rel=3D"nofollow" t=
arget=3D"_blank" onmousedown=3D"this.href=3D&#39;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&#39;;return true;" on=
click=3D"this.href=3D&#39;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&#39;;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&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/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--

.
