Created on 2010-03-26.00:00:00 last changed 161 months ago
Proposed resolution:
Change Table 26 — Hash requirements [tab:hash] as indicated:
Table 26 — Hash requirements [tab:hash] Expression Return type Requirement h(k) size_t Shall not throw exceptions.[…]
Add to [unord.hash] p. 1 a new bullet:
1 The unordered associative containers defined in Clause [unord] use specializations of the class template hash as the default hash function. For all object types Key for which there exists a specialization hash<Key>, the instantiation hash<Key> shall:
- satisfy the Hash requirements ([hash.requirements]), with Key as the function call argument type, the DefaultConstructible requirements (Table [defaultconstructible]), the CopyAssignable requirements (Table [copyassignable]),
- be swappable ([swappable.requirements]) for lvalues,
- provide two nested types result_type and argument_type which shall be synonyms for size_t and Key, respectively,
- satisfy the requirement that if k1 == k2 is true, h(k1) == h(k2) is also true, where h is an object of type hash<Key> and k1 and k2 are objects of type Key,
.- satisfy the requirement that the expression h(k), where h is an object of type hash<Key> and k is an object of type Key, shall not throw an exception, unless hash<Key> is a user-defined specialization that depends on at least one user-defined type.
[ 2010-11-11 Daniel asks the working group whether they would prefer a replacement for the second bullet of the proposed resolution (a result of discussing this with Alberto) of the form: ]
Add to [unord.hash]/1 a new bullet:
1 The unordered associative containers defined in Clause 23.5 use specializations of the class template hash as the default hash function. For all object types Key for which there exists a specialization hash<Key>, the instantiation hash<Key> shall:
- satisfy the Hash requirements (20.2.4), with Key as the function call argument type, the DefaultConstructible requirements (33), the CopyAssignable requirements (37),
- be swappable (20.2.2) for lvalues,
- provide two nested types result_type and argument_type which shall be synonyms for size_t and Key, respectively,
- satisfy the requirement that if k1 == k2 is true, h(k1) == h(k2) is also true, where h is an object of type hash<Key> and k1 and k2 are objects of type Key,
.- satisfy the requirement noexcept(h(k)) == true, where h is an object of type hash<Key> and k is an object of type Key, unless hash<Key> is a user-defined specialization that depends on at least one user-defined type.
The currently added Hash requirements demand in Table 40 — Hash requirements [hash]:
Table 40 — Hash requirements [hash] Expression Return type Requirement h(k) size_t Shall not throw exceptions. [..]
While it surely is a generally accepted idea that hash function objects should not throw exceptions, this basic constraint for such a fundamental requirement set does neither match the current library policy nor real world cases:
The new definition goes beyond the original hash requirements as specified by SGI library in regard to the exception requirement:
Even though the majority of all known move, swap, and hash functions won't throw and in some cases must not throw, it seems like unnecessary over-constraining the definition of a Hash functor not to propagate exceptions in any case and it contradicts the general principle of C++ to impose such a requirement for this kind of fundamental requirement.
History | |||
---|---|---|---|
Date | User | Action | Args |
2011-08-23 20:07:26 | admin | set | status: wp -> c++11 |
2011-04-11 11:23:23 | admin | set | status: voting -> wp |
2011-03-05 15:24:28 | admin | set | status: ready -> voting |
2010-11-13 16:25:04 | admin | set | status: review -> ready |
2010-11-11 22:04:40 | admin | set | messages: + msg5338 |
2010-11-11 13:29:36 | admin | set | status: open -> review |
2010-11-10 13:35:38 | admin | set | status: nad future -> open |
2010-11-09 01:35:58 | admin | set | status: new -> nad future |
2010-10-21 18:28:33 | admin | set | messages: + msg1620 |
2010-03-26 00:00:00 | admin | create |