Opened 8 years ago

Closed 5 years ago

#11145 closed Bugs (fixed)

Unable to hash char16_t or char32_t

Reported by: dave.lowell@… Owned by: Daniel James
Milestone: To Be Determined Component: hash
Version: Boost 1.56.0 Severity: Problem
Keywords: Cc:

Description

boost::hash doesn't work on char16_t or char32_t data. This did work previously (at least as recently as boost 1.49). There doesn't seem to have been a hash_value overload for them, but it looks like they were implicitly converted to something that was supported.

Reproduction Code

#include <boost/functional/hash.hpp> 
#include <string> 

void foo() { 
    std::u16string s; 
    auto h = boost::hash<decltype(s)>()(s); 
} 

Change History (5)

comment:1 by dave.lowell@…, 8 years ago

I have a patched version of boost/functional/hash/hash.hpp which works with char16_t and char32_t, but I can't seem to attach it (the spam filter is unhappy with it).

Basically the change is the addition of the following:

#if !defined(BOOST_NO_CXX11_CHAR16_T)
        template <> struct basic_numbers<char16_t> :
            boost::hash_detail::enable_hash_value {};
#endif
	
#if !defined(BOOST_NO_CXX11_CHAR32_T)
        template <> struct basic_numbers<char32_t> :
            boost::hash_detail::enable_hash_value {};
#endif

comment:2 by John Maddock, 7 years ago

This one has just hit me as well... any progress?

comment:3 by Tino Didriksen <mail@…>, 5 years ago

Just ran into this as well. Newer ICU will typedef UChar as char16_t, which then means UChar is no longer hashable by Boost. Please fix...

comment:4 by anonymous, 5 years ago

I just added an implementation to the develop branch,

comment:5 by Daniel James, 5 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.