本文介绍了比较std :: functions的相等性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何比较两个C ++ 11 std :: function s与 operator == ,并返回 true 如果函数都指向相同的函数指针?

How can I compare two C++11 std::functions with operator==, and return true if both of said functions refer to the same function pointer?

推荐答案

std :: function 比较一个 std :: function 与一个空指针,就我可以告诉标准不提供任何细节为什么。

operator== for std::function compares a std::function with a null pointer, as far as I can tell the standard does not provide any details as to why.

虽然,这个提升常见问题项目,提供了一个基本原理,据我所知,应该适用于。引用常见问题解答:

Although, this boost FAQ entry, Why can't I compare boost::function objects with operator== or operator!=? provides a rationale and as far as I can tell should be applicable to std::function as well. Quoting the FAQ:

然后概述类似于Preet的请求解决方案,并继续说:

it then outlines requested solutions similar to Preet's and goes on to say:

并解释为什么必须在赋值运算符或构造函数中处理,然后继续说:

and explains why this has to has to be dealt with in either the assignment operator or constructor and then goes on to say:

更新

在,它很漂亮,但与boost常见问题一致,并说:

Found a standards rationale in Accessing the target of a tr1::function object, which is pretty old but is consistent with the boost FAQ and says:

这篇关于比较std :: functions的相等性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 09:54