Nov 20, 2013

[c++14][NOTE] pointer to function do have linkage in C++14

excerpt from Scott Meyers' New C++ Closures as Function Pointers: Capture‐less closures implicitly convert to function pointers:
 
int (*fp)(int) = [](int x) { return x * x; };
Such closures can be treated like functions.
 No need for std::function to refer to them.
 No captures ⇒ no stored pointers or references ⇒ no dangling.
 Often useful for callbacks with C‐like APIs:
 
int atexit(void (*f)()) noexcept; // from <cstdlib>
std::atexit([]{ logMsg("Shutting down..."); });
In C++11, function pointer linkage not specified ⇒ possible linkage problems.
 C++14 specifies C++ linkage.
noexcept akin to throw(), but enables more optimizations.
 Violated noexcept ⇒ terminate.
 Exception specifications now deprecated.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.