Skip to content

Hash of *std::*string_view must equal hash of corresponding std::string object #58

Description

@martinmoene

std::hash<std::string_view> on cppreference

Section 24.4.5 in C++ 17 working draft N4659: Hash support:

Note: The hash value of a string view object is equal to the hash value of the corresponding string object.

Currently the following tests fail and although it's not std::string_view, you might consider this for core::string_view.

  SECTION("hash-std::string") {
      CHECK( std::hash<core::string_view>()("hello") == std::hash<std::string>()("hello") );
      CHECK( std::hash<core::string_view>()("world") == std::hash<std::string>()("world") );
  }
prompt> test-string-view.exe --reporter compact
string-view.cpp:383: failed: std::hash<core::string_view>()("hello") == std::hash<std::string>()("hello") for: 2191231550387646743 == 2762169579135187400
string-view.cpp:384: failed: std::hash<core::string_view>()("world") == std::hash<std::string>()("world") for: 5568329560871645431 == 8751027807033337960
Failed 1 test case, failed 2 assertions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions