【发布时间】:2014-07-13 13:20:24
【问题描述】:
以下情况可以使用哪种算法或算法组合?
struct Term
{
int ix;
double f;
};
std::vector<Term> terms = <intitalize terms>;
std::vector< int > termIxVector;
// NEED get all `ix` from the `terms` where term.f < 1.0,
// and insert 'ix' result to termIxVector.
//i.e. equavalent this loop:
for(std::size_t i = 0; i < terms.size(); ++i)
if ( terms[i].f < 1.0 )
termIxVector.push_back(terms[i].ix);
std::copy_if 仅复制 Term 结构。 std::transform - 不支持谓词。
【问题讨论】:
-
一个普通的(基于范围的)for循环应该足够了。或者
std::for_each,如果你真的想要<algorithm>。这不适合你吗?