- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有这门课
class Point2D
{
public:
bool isValid();
// ...
private:
double x_, y_;
};
我有一个 std::vector< Point2D >
我想删除无效点,现在我这样做:
bool invalid ( const Point2D& p )
{
return !p.isValid();
}
void f()
{
std::vector< Point2D > points;
// fill points
points.erase( std::remove_if( points.begin(), points.end(), invalid ), points.end() );
// use valid points
}
是否有一种标准的方法(漂亮地)做到这一点,例如不需要“复制”类方法的功能 Point2D::isValid
?
也许使用 C++11 lambda(我对 lambda 不是很熟悉)?
最佳答案
试试这个:
points.erase(std::remove_if(points.begin(),
points.end(),
std::not1(std::mem_fun_ref(&Point2D::isValid))),
points.end());
关于c++ - remove_if 的惯用 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6263044/
我对 Clojure 和函数式编程有了大约一周的了解——我的所有背景都是 OOP。我想利用 Clojure 备受争议的易读性和固有逻辑,但现在我不知道我是否成功地做到了这一点,只是没有完全理解它,或者
场景: val col: IndexedSeq[Array[Char]] = for (i = 0 && arr(last.y)(west) == '.') { arr(last.y)(w
我正面临 AngularJS、服务和范围的“问题”。 这不是一个真正的问题(我找到了几种使其工作的方法),但我想知道我是否在做正确的事情,或者我正在做的事情是否会导致将来出现问题 我有一个保存一些全局
进行以下数据结构转换的“Rubyist”方法是什么: 我有 incoming = [ {:date => 20090501, :width => 2}, {:
如何在 go 中编写返回集合最小值的函数?我不只是在寻找解决方案(我知道我可以在遍历第一个元素时只初始化最小值,然后设置一个我初始化最小值的 bool 变量),而是一个惯用的解决方案。由于 go 没有
好的,我知道我应该对我的特定应用程序进行基准测试,等等,但是: -Xmx 的默认 JVM 设置、默认垃圾收集器等,对于大多数典型的 Java 程序来说是合理的默认设置,并且可能不适合惯用的 Scala
既然 shared_ptr 在 tr1 中,你认为 std::auto_ptr 的使用会发生什么?它们都有不同的用例,但 auto_ptr 的所有用例也都可以用 shared_ptr 解决。你会放弃
这个问题在这里已经有了答案: What are the differences between type() and isinstance()? (8 个回答) 关闭 9 年前。 我需要知道 Pyth
在指定和创建数字函数时,是否有关于何时返回 null 以及何时返回 NaN 的任何 C# 惯用准则,当两者似乎都是有效输出时。 导致这个问题的具体例子是我正在为 Enumerable 集合创建一个百分
这个问题在这里已经有了答案: Retrieving the top 100 numbers from one hundred million of numbers [duplicate] (12 个
我可以通过反射检索方法,以某种方式将其与目标对象结合起来,并将其作为看起来像 Scala 中的函数的东西返回(即您可以使用括号调用它)吗?参数列表是可变的。它不一定是“一流”函数(我已经更新了问题),
我是一名优秀的程序员,十分优秀!