On Tue, May 26, 2026, at 1:33 PM, Robert Dubner wrote: > Pietro, thanks. It looks good, and it passes my local testing.
Thanks for the review. Should I push all 3 patches in the series or just the third one? Better safe than sorry :) pietro >> -----Original Message----- >> From: Pietro Monteiro <[email protected]> >> Sent: Monday, May 25, 2026 21:01 >> To: [email protected] >> Cc: Pietro Monteiro <[email protected]>; Robert Dubner >> <[email protected]>; James K . Lowden <[email protected]> >> Subject: [PATCH 3/3] libgcobol: Add hash function for enum > cbl_enconding_t >> >> GCC versions before 6.1 don't support std::hash for enum types. Add a >> hash function for enum cbl_enconding_t based in the underlying type. >> Use it for the unordered_map where cbl_enconding_t is the key type. >> Also add a typedef to make it easier to use the long type with > templates. >> >> libgcobol/ChangeLog: >> >> * charmaps.cc (__gg__get_charmap): Use cbl_encoding_charmap_map. >> (typedef cbl_encoding_charmap_map): New. >> * encodings.h (struct cbl_encoding_t_hash): New. >> >> Signed-off-by: Pietro Monteiro <[email protected]> >> --- >> libgcobol/charmaps.cc | 8 +++++--- >> libgcobol/encodings.h | 11 +++++++++++ >> 2 files changed, 16 insertions(+), 3 deletions(-) >> >> diff --git a/libgcobol/charmaps.cc b/libgcobol/charmaps.cc >> index 8aa42e3234e..3e22c669a86 100644 >> --- a/libgcobol/charmaps.cc >> +++ b/libgcobol/charmaps.cc >> @@ -1726,8 +1726,11 @@ __gg__miconverter( cbl_encoding_t from, >> return retval; >> } >> >> +typedef std::unordered_map<cbl_encoding_t, charmap_t *, > cbl_encoding_t_hash> >> +cbl_encoding_charmap_map; >> + >> static >> -std::unordered_map<cbl_encoding_t, charmap_t *>map_of_encodings; >> +cbl_encoding_charmap_map map_of_encodings; >> >> charmap_t * >> __gg__get_charmap(cbl_encoding_t encoding) >> @@ -1749,8 +1752,7 @@ __gg__get_charmap(cbl_encoding_t encoding) >> } >> >> charmap_t *retval; >> - std::unordered_map<cbl_encoding_t, charmap_t *>::const_iterator it >> - = map_of_encodings.find(encoding); >> + cbl_encoding_charmap_map::const_iterator it = >> map_of_encodings.find(encoding); >> if( it != map_of_encodings.end() ) >> { >> retval = it->second; >> diff --git a/libgcobol/encodings.h b/libgcobol/encodings.h >> index 3a7e40cef83..cf46d83981a 100644 >> --- a/libgcobol/encodings.h >> +++ b/libgcobol/encodings.h >> @@ -31,6 +31,8 @@ >> #ifndef _ENCODINGS_H_ >> #define _ENCODINGS_H_ >> >> +#include <type_traits> >> + >> enum cbl_encoding_t { >> no_encoding_e, >> custom_encoding_e, >> @@ -1212,4 +1214,13 @@ struct encodings_t { >> char name[32]; >> }; >> >> +struct cbl_encoding_t_hash { >> + using hashed_type = std::underlying_type<cbl_encoding_t>::type; >> + size_t >> + operator()(cbl_encoding_t e) const noexcept >> + { >> + return std::hash<hashed_type>{}(static_cast<hashed_type>(e)); >> + } >> +}; >> + >> #endif >> -- >> 2.43.0
