1. Design decisions
-
Proposed hash specializations give the same hash value for different containers with the same content. This may be useful for users to compare different containers in a fast maner. This also allows users to have heterogeneous searches in unordered maps by keys of different type.
-
We do not enable
for unordered_set, unordered_map, unordered_multiset, unordered_multimap because of the hashing collisions and buckets count. Position of the elment depends on those two factors, which leads to different hashes for containers with the same content.hash -
We do not enable hash for
andstack
adapters for now.queue
2. Proposed wording
Add a new Section "19.4.6, Hash support [pair.hash]", with following content:
template < typename A , typename B > struct hash < pair < A , B >> ;
Enabled if specializations
and
are both enabled, and disabled otherwise.
Let
denote a
type,
denote a value of type
. For enabled specialization
the following holds:
==
.
Add a new Section "19.5.3.11, Hash support [tuple.hash]", with following content:
template < typename ... T > struct hash < tuple < T ... >> ;
Enabled if specialization
is enabled for every template argument
in the parameter pack, and disabled otherwise.
Add a new Section "21.3.7.7, Hash support [array.hash]", with following content:
template < typename T , std :: size_t N > struct hash < array < T , N >> ;
Enabled if specialization
is enabled, and disabled otherwise.
Add a new Section "21.3.8.6, Hash support [deque.hash]", with following content:
template < typename T , typename Allocator > struct hash < deque < T , Allocator >> ;
Enabled if specialization
is enabled, and disabled otherwise.
Add a new Section "21.3.9.8, Hash support [forward_list.hash]", with following content:
template < typename T , typename Allocator > struct hash < forward_list < T , Allocator >> ;
Enabled if specialization
is enabled, and disabled otherwise.
Add a new Section "21.3.10.7, Hash support [list.hash]", with following content:
template < typename T , typename Allocator > struct hash < list < T , Allocator >> ;
Enabled if specialization
is enabled, and disabled otherwise.
Add a new Section "21.3.11.7, Hash support [vector.hash]", with following content:
template < typename T , typename Allocator > struct hash < vector < T , Allocator >> ;
Enabled if specialization
is enabled, and disabled otherwise.
Add a new Section "21.4.4.6, Hash support [map.hash]", with following content:
template < typename Key , typename T , typename Compare , typename Allocator > struct hash < map < Key , T , Compare , Allocator >> ;
Enabled if specialization if specializations
and
are both enabled, and disabled otherwise.
Add a new Section "21.4.5.5, Hash support [multimap.hash]", with following content:
template < typename Key , typename T , typename Compare , typename Allocator > struct hash < multimap < Key , T , Compare , Allocator >> ;
Enabled if specialization if specializations
and
are both enabled, and disabled otherwise.
Add a new Section "21.4.6.4, Hash support [set.hash]", with following content:
template < typename Key , typename Compare , typename Allocator > struct hash < set < Key , Compare , Allocator >> ;
Enabled if specialization if specializations
is enabled, and disabled otherwise.
Add a new Section "21.4.7.4, Hash support [multiset.hash]", with following content:
template < typename Key , typename Compare , typename Allocator > struct hash < multiset < Key , Compare , Allocator >> ;
Enabled if specialization if specializations
is enabled, and disabled otherwise.
Add a new Section "25.7.2.9, Hash support [valarray.hash]", with following content:
template < typename T > struct hash < valarray < T >> ;
Enabled if specialization
is enabled, and disabled otherwise.
Remove a paragraph from Section "20.3.5, Hash support [basic.string.hash]", with following content:
template <> struct hash < string > ; template <> struct hash < u8string > ; template <> struct hash < u16string > ; template <> struct hash < u32string > ; template <> struct hash < wstring > ; template <> struct hash < pmr :: string > ; template <> struct hash < pmr :: u8string > ; template <> struct hash < pmr :: u16string > ; template <> struct hash < pmr :: u32string > ; template <> struct hash < pmr :: wstring > ;
Add a new paragraph to Section "20.3.5, Hash support [basic.string.hash]", with following content:
template < typename charT , typename Allocator > struct hash < basic_string < charT , char_traits < charT > , Allocator >> ;
Enabled if specialization
is enabled, and disabled otherwise.
Add a new paragraph to "21.2.1, General container requirements [container.requirements.general]", with following content:
Let
denote a container type,
denote a value of type
,
denote a
value of all the values of
from
to
where
equals
for any i in range
. For enabled specialization
the following holds:
==
.
3. Possible implementation
Some possible implementations can be found in Boost.Hash library.