Ori*_*ent 11 c++ algorithm stl convolution
是否有一个很好的算法实现来计算C++ STL(甚至是boost)中两个范围的卷积?即原型(两个范围的卷积a..b和c..d)的东西:
template< class Iterator >
void convolution(Iterator a, Iterator b, Iterator c, Iterator d);
Run Code Online (Sandbox Code Playgroud)
它修改了a..b范围
是的 std::transform
std::transform(a, b, c, a, Op);
// a b is the the first input range
// c is the start of the second range (which must be at least as large as (b-a)
//
// We then use a as the output iterator as well.
// Op is a BinaryFunction
Run Code Online (Sandbox Code Playgroud)
回答评论中关于如何执行状态累积的评论:
struct Operator
{
State& state;
Operator(Sate& state) : state(state) {}
Type operator()(TypeR1 const& r1Value, TypeR2 const& r2Value) const
{
Plop(state, r1Value, r2Value);
return Convolute(state, r2Value, r2Value);
}
};
State theState = 0;
Operator Op(theState);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4151 次 |
| 最近记录: |