<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<title>Converting Lambdas to Function Pointers</title>
</head>
<body>
<h1>Converting Lambdas to Function Pointers</h1>

<p>
ISO/IEC JTC1 SC22 WG21 N3052 = 10-0042 - 2010-03-09
</p>

<p>
Lawrence Crowl, crowl@google.com, Lawrence@Crowl.org
<br>
Alisdair Meredith, public@alisdairm.net
</p>

<p>
This paper
is updated from
<a href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2010/n3043.html">N3043</a> = 10-0033
which extracts a generally uncontroversial portion of
<a href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2009/n2989.html">N2989</a> = 09-0179.
</p>


<h2>Introduction</h2>

<p>
The semantics of a lambda with an empty capture list and a function
are nearly uniform.
This uniformity was noted in U.K.&nbsp;national body comment 226.
Exposing this uniformity 
would allow programmers to use lambdas
and exploit existing function-based interfaces.
</p>
<blockquote>
<p>
<i>Problem:</i>
A lambda with an empty capture list has identical semantics
to a regular function type.
By requiring this mapping we get an efficient lambda type with a known API
that is also compatible with existing operating system and C library functions.
</p>
<p>
<i>Resolution:</i>
Add a new paragraph:
"A lambda expression with an empty capture set
shall be convertible to pointer to function type R(P),
where R is the return type and P is the parameter-type-list
of the lambda expression."
Additionally it might be good to
(a) allow conversion to function reference and
(b) allow extern "C" function pointer types.
</p>
</blockquote>

<p>
We adopt the suggested resolution.
</p>


<h2>Proposed Wording</h2>

<p>
The proposed wording shows changes from working draft
<a href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2010/n3035.pdf">N3035</a>.
</p>


<h3><a name="expr.prim.lambda">5.1.2 Lambda expressions [expr.prim.lambda]</a></h3>

<p>
Add a new paragraph after paragraph 5.
The intent of this edit is
to obtain a closure-to-function-pointer conversion
for a lambda with no <var>lambda-capture</var>.
</p>

<blockquote>
<p><ins>
The closure type for a <var>lambda-expression</var>
with no <var>lambda-capture</var>
has a public non-virtual non-explicit const conversion function
to pointer to function having
the same parameter and return types
as the closure type's function call operator.
The value returned by this conversion function
shall be the address of a function that, when invoked,
has the same effect as invoking the closure type's function call operator.
</ins></p>
</blockquote>


</body>
</html>
