std::function encapsulates arbitrary callable objects, presenting a unique challenge for equality comparison. Implementing such comparisons would necessitate equality comparability for all callable types, which would impose a significant burden on implementors. Moreover, equal functionality could yield non-equal comparisons based on differing argument binding orders. Therefore, the impossible task of guaranteeing equivalence in all cases prohibits equality comparability.
The "possible hole in the type system" mentioned in the C 11 draft likely refers to the inherent ambiguity in implicit conversions. Deleting equality operators and coercing explicit use ensures the absence of valid code generated from their invocation.
Unlike std::function, std::shared_ptr possesses a clearly defined equality semantics. Two pointers are equal precisely when both are empty or both refer to the same object. This well-defined behavior allows for straightforward and meaningful equality comparisons.
The above is the detailed content of Why Can\'t I Compare `std::function` Objects for Equality?. For more information, please follow other related articles on the PHP Chinese website!