本文介绍了如何比较函数对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 如果两个函数对象持有相同的函数引用,如何比较?How do I compare if two function objects hold the same function reference?struct A { void b(){}}int main() { A a; auto f1 = std::bind(&A::b, a); auto f2 = std::bind(&A::b, a); f1 == f2 // ???} 推荐答案 std :: bind 仅保证可调用并且成员类型为 result_type 。没有符合标准的比较绑定函数的方法。Result of std::bind guarantees only to be callable and to have member type result_type. There is no standard-conformant way to compare binded functions.未指定类型T的函数对象,其中 std :: is_bind_expression :: value == true,并且可以存储在 std :: function中。如果f和所有arg都是可移动的,则对象是可移动的,,否则是可复制的。该类型定义了以下成员:A function object of unspecified type T, for which std::is_bind_expression::value == true, and which can be stored in std::function. The object is movable if f and all args are movable, and is copyable otherwise. The type defines the following members: http://en.cppreference.com/w/cpp/utility/functional/bind 这篇关于如何比较函数对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-31 17:24