Skip to content

libc++: hash specializations for basic_string(_view) are enabled for all possible element types #55823

@frederick-vs-ja

Description

@frederick-vs-ja

E.g. this program compiles (godbolt link):

#include <string>
#include <string_view>

int main()
{
    using intstring = std::basic_string<int>;
    using intstring_view = std::basic_string_view<int>;
    (void)std::hash<intstring>{}(intstring{});
    (void)std::hash<intstring_view>{}(intstring_view{});
}

It seems intended to restrict the enabled specializations for basic_string(_view) of encoded character types (char, char8_t, char16_t, char32_t, and wchar_t) only:

  • The C++11~17 standard originally only enabled full specializations for std::string etc.
  • LWG2978 (DR against C++17) enabled specializations for pmr types.
  • And then P0482R6 provided enabled specializations for std::u8string and std::pmr::u8string.
  • There is now an open issue LWG3705 (possibly intended to be DR against C++11) that wants to enable specializations for basic_string with all allocators, but not all element types.

I suppose that libc++ should restrict enabled specializations to basic_string(_view) of encoded character types only.

Metadata

Metadata

Assignees

No one assigned

    Labels

    libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions