Title
string_view objects and strings should yield the same hash values
Status
resolved
Section
[string.view.hash]
Submitter
Nicolai Josuttis

Created on 2016-11-09.00:00:00 last changed 98 months ago

Messages

Date: 2016-11-21.17:34:16

Proposed resolution:

This wording is relative to N4606.

A more formal formulation would be:

For any sv of type SV (being string_view, u16string_view, u32string_view, or wstring_view) and s of the corresponding type S (being string, u16string, u32string, or wstring), hash<SV>()(sv) == hash<S>()(s).

  1. Edit [string.view.hash] as indicated:

    template<> struct hash<string_view>;
    template<> struct hash<u16string_view>;
    template<> struct hash<u32string_view>;
    template<> struct hash<wstring_view>>;
    

    -1- The template specializations shall meet the requirements of class template hash ([unord.hash]). The hash values shall be the same as the hash values for the corresponding string class ([basic.string.hash]).

Date: 2016-11-15.00:00:00

[ 2016-11-12, Issaquah ]

Resolved by P0513R0

Date: 2016-11-09.00:00:00

Under certain conditions we want to be able to use string_view instead of string. As a consequence both types should behave the same as long we talk about value specific behavior (if possible). For this reason, we should require that both strings and string_view yield the same hash values.

Should be solved in C++17 to ensure that following this use does not require to change hash values (which is allowed but possibly unfortunate).

History
Date User Action Args
2016-11-21 17:34:16adminsetmessages: + msg8681
2016-11-21 17:34:16adminsetstatus: new -> resolved
2016-11-09 19:27:52adminsetmessages: + msg8589
2016-11-09 00:00:00admincreate