RCPP vs普通C ++:标头标志可用吗?

时间:2019-02-26 14:51:48

标签: r rcpp

我是Rcpp的初学者(尽管在R和C ++方面都有一定的经验),并且正在尝试编写一些可在Rcpp和本机C ++中使用的代码。

这样,我正在编写一些包装函数,这些包装函数返回从各种std容器中创建的数据帧,数值向量等。

我想要这样,以便我可以在某处设置一个标志,或者具有一个标志来自动检测代码是在本机C ++还是Rcpp中使用。

我想知道是否存在这样的标志,还是应该继续创建一个?

最后,我想知道这是否是我想要实现的最佳方法?

编辑:

这是一个非常人为的例子:

#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::plugins(cpp11)]]

#include <vector>
#include <functional>
#include <algorithm>

#define RCPP
std::vector<double> multbyTwo(std::vector<double> input) {
  std::transform(input.begin(), input.end(), input.begin(), std::bind(std::multiplies<double>(), std::placeholders::_1, 2));
  return input;
}

#ifdef RCPP
// [[Rcpp::export]]
NumericVector timesTwo(NumericVector input) {
  return wrap(multbyTwo(as<std::vector<double> >(input)));
}
#endif // RCPP

/***R
print(timesTwo(10))
***/

这就是我的意思-用Rcpp包装一个纯C ++函数。 (我知道在这种特定情况下会有隐式转换,但是我所要构建的功能不会有这种转换)

0 个答案:

没有答案