Std :: string_view compiles hash time

It seems std :: hash functions for a C ++ 17 string_view string are not constexpr.

It seems to me that the string representation associated with const char [] can be hashed at compile time (which would be very nice), or is there anything that prevents this?

+4
source share
1 answer

Since C ++ 14 (see 17.6.3.4 Hash Requirements, Table 26), we have:

The return value will depend only on the argument k for the duration of the program. [Note: Thus, all evaluations of the expression h (k) with the same value for k give the same result for a given execution of the program . - final note]

Two different executions can produce different hashes :

Hashing functions are necessary only to obtain the same result for the same input within the same program execution ; this allows salty hashes to prevent DoS attacks in a collision .

This behavior is useful for mitigating a hash collision based on a DoS attack .

More details

Here is the wording of the concept requirements Hashfrom the C ++ 17 standard:

k . [: , h (k) k . - ]

. std::hash .

N3242 2011-02-28 , " ":

. k. [: , h (k) k . -

, " " " " "2291. std:: hash DoS .

AFAIU, std::hash , my::secure_hash.

+8

All Articles