Movatterモバイル変換


[0]ホーム

URL:



This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofC++11 status.

1240. Deleted comparison functions ofstd::function not needed

Section: 22.10.17.3[func.wrap.func]Status:C++11Submitter: Daniel KrüglerOpened: 2009-10-18Last modified: 2016-01-28

Priority:Not Prioritized

View all otherissues in [func.wrap.func].

View all issues withC++11 status.

Discussion:

The class templatestd::function contains the following memberdeclarations:

// 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;

The leading comment here is part of the history ofstd::function, whichwas introduced withN1402.During that time no explicit conversion functions existed, and the"safe-bool" idiom (based on pointers-to-member) was a populartechnique. The only disadvantage of this idiom was that given twoobjectsf1 andf2 of typestd::function the expression

f1 == f2;

was well-formed, just because the built-inoperator== for pointer to memberwas considered after a single user-defined conversion. To fix this, anoverload set ofundefined 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 betterdiagnostic mechanism to fix this issue.

The central point of this issue is, that with the replacement of thesafe-bool idiom by explicit conversion to bool the original "hole in thetype system" does no longer exist and therefore the comment is wrong andthe superfluous function definitions should be removed as well. Anexplicit conversion function is considered in direct-initializationsituations only, which indirectly contain the so-called "contextualconversion to bool" (7.3[conv]/3). These conversions are not considered for== or!= as defined by the core language.

[Post-Rapperswil]

Moved to Tentatively Ready after 5 positive votes on c++std-lib.

[Adopted at 2010-11 Batavia]

Proposed resolution:

In 22.10.17.3[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;

[8]ページ先頭

©2009-2026 Movatter.jp