RcppCore/Rcpp — pull request #162 by cauthmann (2014-08-06 11:34:39+00:00)
Title: Support std::function in InternalFunction

c++11 allows ad hoc creation of functions using lambda expressions and std::bind. Since these can carry a context, they cannot be represented by a function pointer, only by a std::function object.

These patches add a new constructor to InternalFunction which takes a std::function object. A few internal changes were required to make this possible: since we cannot create a full CppFunction without a function pointer, the functionality required by InternalFunction has been moved into a base class.

There is no good compile-time way to check for std::function support. C++11 support in the compiler is not sufficient; one needs support in the headers and libstd++/libc++/whatever. Checking for the existence of the header is pointless, since that header existed in c++98. As such, this code requires the user to
#define RCPP_USE_STD_FUNCTION
#include
This is a bit ugly, but as long as there are people with c++11 compilers but without full c++11 headers, I see no better way.

The generator script for the new file is committed to
https://github.com/cauthmann/rcpp-scripts/tree/std_function
I'll create a pull request if/when this one is merged.

All unit tests still pass, valgrind'ing my app shows no errors.