Understanding Safety of Function Pointers vs. Addresses of Functions
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jul 9 05:24:46 PDT 2015
On 7/9/15 4:44 AM, "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm at gmx.net>" wrote:
> On Wednesday, 8 July 2015 at 21:04:27 UTC, jmh530 wrote:
>> On Wednesday, 8 July 2015 at 18:31:00 UTC, Steven Schveighoffer wrote:
>>> You can use a function lambda:
>>>
>>> auto fp = (real a) => cos(a);
>>>
>>> Note, I had to put (real a) even though I would have expected "a =>
>>> cos(a)" to work.
>>>
>>
>> Interesting. You have to put real because there is also a float and
>> double version of cos.
>
> Even if there are no overloads, you'd still need to specify the type.
> That's because `a => cos(a)` is not a function, but a function template,
> and therefore can't be store in a variable.
I didn't know this! I thought it would infer the type if there wasn't
any overloads (or in this case, I thought there was a weird issue with
the fact that cos is intrinsic).
This is good to know.
-Steve
More information about the Digitalmars-d-learn
mailing list