Created on 2009-10-18.00:00:00 last changed 162 months ago
Proposed resolution:
In [func.wrap.func]/1, class function change as indicated:
// 20.7.15.2.3, function capacity: explicit operator bool() const;// deleted overloads close possible hole in the type systemtemplate<class R2, class... ArgTypes2>bool operator==(const function<R2(ArgTypes2...)>&) = delete;template<class R2, class... ArgTypes2>bool operator!=(const function<R2(ArgTypes2...)>&) = delete;
[ Adopted at 2010-11 Batavia ]
[ Post-Rapperswil ]
Moved to Tentatively Ready after 5 positive votes on c++std-lib.
The class template std::function contains the following member declarations:
// deleted overloads close possible hole in the type system template<class R2, class... ArgTypes2> bool operator==(const function<R2(ArgTypes2...)>&) = delete; template<class R2, class... ArgTypes2> bool operator!=(const function<R2(ArgTypes2...)>&) = delete;
The leading comment here is part of the history of std::function, which was introduced with N1402. During that time no explicit conversion functions existed, and the "safe-bool" idiom (based on pointers-to-member) was a popular technique. The only disadvantage of this idiom was that given two objects f1 and f2 of type std::function the expression
f1 == f2;
was well-formed, just because the built-in operator== for pointer to member was considered after a single user-defined conversion. To fix this, an overload set of undefined comparison functions was added, such that overload resolution would prefer those ending up in a linkage error. The new language facility of deleted functions provided a much better diagnostic mechanism to fix this issue.
The central point of this issue is, that with the replacement of the safe-bool idiom by explicit conversion to bool the original "hole in the type system" does no longer exist and therefore the comment is wrong and the superfluous function definitions should be removed as well. An explicit conversion function is considered in direct-initialization situations only, which indirectly contain the so-called "contextual conversion to bool" ([conv]/3). These conversions are not considered for == or != as defined by the core language.
History | |||
---|---|---|---|
Date | User | Action | Args |
2011-08-23 20:07:26 | admin | set | status: wp -> c++11 |
2010-11-23 13:22:14 | admin | set | messages: + msg5399 |
2010-11-14 13:10:57 | admin | set | status: voting -> wp |
2010-11-08 14:14:39 | admin | set | status: ready -> voting |
2010-10-21 19:06:53 | admin | set | messages: + msg4764 |
2010-10-21 19:06:53 | admin | set | status: new -> ready |
2010-10-21 18:28:33 | admin | set | messages: + msg1278 |
2009-10-18 00:00:00 | admin | create |