Topic: Explicit function arguments


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Mon, 31 Dec 2012 16:43:14 -0800 (PST)
Raw View
------=_Part_1_9514850.1357000994685
Content-Type: text/plain; charset=ISO-8859-1

Currently, overload resolution allows arguments passed to functions to use
any available implicit conversions. C++ has ways to force certain
conversions to be explicit. But it doesn't have a way to say, "I don't want
the user to use anything except the exact type I said." If implicit
conversions exist, they will be used, and you can't stop it.

The syntax for this would be simple:

void FuncName(explicit int foo);

This function would take an int. Exactly and only an int. Not a char,
short, long, long long, or anything else. It must be an `int`.

--




------=_Part_1_9514850.1357000994685
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Currently, overload resolution allows arguments passed to functions to use =
any available implicit conversions. C++ has ways to force certain conversio=
ns to be explicit. But it doesn't have a way to say, "I don't want the user=
 to use anything except the exact type I said." If implicit conversions exi=
st, they will be used, and you can't stop it.<br><br>The syntax for this wo=
uld be simple:<br><br><div class=3D"prettyprint" style=3D"background-color:=
 rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid;=
 border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><di=
v class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-=
prettify">void</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">FuncN=
ame</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">explicit</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> foo</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br></span></div></code></div><br>This function =
would take an int. Exactly and only an int. Not a char, short, long, long l=
ong, or anything else. It must be an `int`.<br>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_1_9514850.1357000994685--

.


Author: Jeffrey Yasskin <jyasskin@googlers.com>
Date: Mon, 31 Dec 2012 17:22:56 -0800
Raw View
--14dae93b62a23b0e5804d22ff85d
Content-Type: text/plain; charset=ISO-8859-1

I've wanted this. You can emulate it using a template with
enable_if<is_same >, but that's not obvious.
On Dec 31, 2012 7:43 PM, "Nicol Bolas" <jmckesson@gmail.com> wrote:

> Currently, overload resolution allows arguments passed to functions to use
> any available implicit conversions. C++ has ways to force certain
> conversions to be explicit. But it doesn't have a way to say, "I don't want
> the user to use anything except the exact type I said." If implicit
> conversions exist, they will be used, and you can't stop it.
>
> The syntax for this would be simple:
>
> void FuncName(explicit int foo);
>
> This function would take an int. Exactly and only an int. Not a char,
> short, long, long long, or anything else. It must be an `int`.
>
> --
>
>
>
>

--




--14dae93b62a23b0e5804d22ff85d
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<p dir=3D"ltr">I&#39;ve wanted this. You can emulate it using a template wi=
th enable_if&lt;is_same &gt;, but that&#39;s not obvious.</p>
<div class=3D"gmail_quote">On Dec 31, 2012 7:43 PM, &quot;Nicol Bolas&quot;=
 &lt;<a href=3D"mailto:jmckesson@gmail.com">jmckesson@gmail.com</a>&gt; wro=
te:<br type=3D"attribution"><blockquote class=3D"gmail_quote" style=3D"marg=
in:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Currently, overload resolution allows arguments passed to functions to use =
any available implicit conversions. C++ has ways to force certain conversio=
ns to be explicit. But it doesn&#39;t have a way to say, &quot;I don&#39;t =
want the user to use anything except the exact type I said.&quot; If implic=
it conversions exist, they will be used, and you can&#39;t stop it.<br>
<br>The syntax for this would be simple:<br><br><div style=3D"background-co=
lor:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;borde=
r-width:1px;word-wrap:break-word"><code><div><span style=3D"color:#008">voi=
d</span><span style> </span><span style=3D"color:#606">FuncName</span><span=
 style=3D"color:#660">(</span><span style=3D"color:#008">explicit</span><sp=
an style> </span><span style=3D"color:#008">int</span><span style> foo</spa=
n><span style=3D"color:#660">);</span><span style><br>
</span></div></code></div><br>This function would take an int. Exactly and =
only an int. Not a char, short, long, long long, or anything else. It must =
be an `int`.<br>

<p></p>

-- <br>
=A0<br>
=A0<br>
=A0<br>
</blockquote></div>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

--14dae93b62a23b0e5804d22ff85d--

.


Author: "R. Martinho Fernandes" <martinho.fernandes@gmail.com>
Date: Mon, 31 Dec 2012 21:26:04 -0800 (PST)
Raw View
------=_Part_686_5186280.1357017964483
Content-Type: text/plain; charset=ISO-8859-1

On Tuesday, January 1, 2013 2:22:56 AM UTC+1, Jeffrey Yasskin wrote:
>
> I've wanted this. You can emulate it using a template with
> enable_if<is_same >, but that's not obvious.
>
You can emulate it using a template *with = delete*:

void FuncName(int foo);
template <typename T>
void FuncName(T foo) = delete;




--




------=_Part_686_5186280.1357017964483
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On Tuesday, January 1, 2013 2:22:56 AM UTC+1, Jeffrey Yasskin wrote:<blockq=
uote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-lef=
t: 1px #ccc solid;padding-left: 1ex;"><p dir=3D"ltr">I've wanted this. You =
can emulate it using a template with enable_if&lt;is_same &gt;, but that's =
not obvious.</p></blockquote><div>You can emulate it using a template *with=
 =3D delete*:<br><br><div class=3D"prettyprint" style=3D"background-color: =
rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; =
border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div=
 class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">void</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">FuncNa=
me</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> foo</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br>template &lt;typename T&gt;<br><=
/span><span style=3D"color: #008;" class=3D"styled-by-prettify">void</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><code cla=
ss=3D"prettyprint"><span style=3D"color: #606;" class=3D"styled-by-prettify=
">FuncName</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
(T </span><span style=3D"color: #000;" class=3D"styled-by-prettify">foo</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">) =3D delete;<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span>=
</code><span style=3D"color: #000;" class=3D"styled-by-prettify"></span></d=
iv></code></div><br><br>&nbsp;</div>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_686_5186280.1357017964483--

.


Author: Beman Dawes <bdawes@acm.org>
Date: Tue, 1 Jan 2013 11:21:39 -0500
Raw View
On Tue, Jan 1, 2013 at 12:26 AM, R. Martinho Fernandes
<martinho.fernandes@gmail.com> wrote:
> On Tuesday, January 1, 2013 2:22:56 AM UTC+1, Jeffrey Yasskin wrote:
>>
>> I've wanted this. You can emulate it using a template with
>> enable_if<is_same >, but that's not obvious.
>
> You can emulate it using a template *with = delete*:
>
> void FuncName(int foo);
> template <typename T>
> void FuncName(T foo) = delete;

These emulations are likely to be viewed as motivations for the void
FuncName(explicit int foo) proposal, because they more verbose and
more expert oriented that the proposal. So be sure to include them in
a proposal.

--Beman

--




.