Skip to content

Support for maps with custom hasher #414

@Yzen90

Description

@Yzen90

If I add a custom hasher to a map this code does not compile:

template <typename T>
struct dummy {
  std::size_t operator()(const T& v) const { return std::hash<T>()(v); }
};

typedef std::unordered_map<int, string> Map;
// typedef std::unordered_map<int, string, dummy<int>> Map; // <-- does not compile

Map map{{1, ""}};

std::string out = rfl::json::write(map);

I get this error with the commented line:

error: vcpkg_installed\x64-windows-static\include\rfl\json\Writer.hpp:121:21: error: static assertion failed due to requirement 'rfl::always_false_v<std::unordered_map<int, std::basic_string<char, std::char_traits, std::allocator>, dummy, std::equal_to, std::allocator<std::pair<const int, std::basic_string<char, std::char_traits, std::allocator>>>>>': Unsupported type.

Can maps with custom hashers be supported?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    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