RCPP - 调用'transform'没有匹配功能
RCPP - no matching function for call to 'transform'
我在Mac上使用RCPP时有问题(在Windows上没有发生问题(。
这是导致错误的C 代码。
#include <Rcpp.h>
using namespace Rcpp;
NumericVector vecpow(const IntegerVector base, const NumericVector exp)
{
NumericVector out(base.size());
std::transform(base.begin(), base.end(), exp.begin(), out.begin(), ::pow);
return out;
}
似乎没有什么太花哨或复杂的。
尝试编译时,我仍然会遇到以下错误:
na_ma.cpp:7:3:错误:呼叫"转换"的匹配功能无 std :: transform(base.begin((,base.end((,exp.begin((,out.begin((,:: pow(; ^~~~~~~~~~~~~~
/library/developer/commandlinetools/usr/include/c /v1/算法:2028:1:注意:候选功能模板不可行:需要4个参数,但提供了5个参数 变换(_inputiterator __first,_inputiterator __last,_outputiterator __ result,_unaryoperation __OP( ^
我想知道如何解决此问题。在搜索解决方案时,我提出了一些建议创建makevars文件的建议 - 但这对我不起作用。
如果有人可以向我解释,为什么我不了解此错误,为什么会发生此错误。
这实际上是C 编译器错误。编译器无法与BinaryOp匹配:: POW,因此将其包装到Lambda中。这对我有用
std::transform(base.cbegin(), base.cend(), exp.cbegin(), out.begin(), [](double a, double b) {return ::pow(a, b); });
如果lambdas不可用,可以尝试制作一个函子(Lambda等同于,请检查https://medium.com/@winwardo/c-lambdas-arent-magic-magic-part-part-part-part-1-b56df2d92d2ad2,https://medium.com/@winwardo/c-lambdas-arent-magic-part-part-2-ce0b48934809(。沿线(未经测试的代码,我不在计算机上(
struct pow_wrapper {
public: double operator()(double a, double b) {
return ::pow(a, b);
}
};
然后尝试
std::transform(base.cbegin(), base.cend(), exp.cbegin(), out.begin(), pow_wrapper());
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- 多态性和功能结合
- 带内存和隔离功能的SQLite
- 在CMakeLists.txt的安装功能中使用.cmake文件有什么用
- 类模板的成员功能的定义在单独的TU中完全专业化
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- 如何在C++中获得"静态纯虚拟"功能?
- 两个文件使用彼此的功能-如何解决
- 我应该实现右值推送功能吗?我应该使用std::move吗
- 如何使用Rcpp将R函数转换为C++函数
- QML按钮点击功能执行顺序
- rcpp函数中的清理时间很长
- 无法理解此 return 语句的功能,没有它就会发生运行时错误
- 有没有可能有一个只有ADL才能找到的非好友功能
- 功能样式转换从 'int' 到 'ItemType' 的匹配转换
- 文件系统:复制功能的速度秘诀是什么
- 使用 Rcpp 复制 dplyr::group_by 的索引功能
- RCPP - 调用'transform'没有匹配功能
- R -RCPP-如何在C 代码中使用分布功能
- 在Rcpp中实现应用功能