Closed Ptomaine closed 6 years ago
Effectively, the problem comes from the type in the allocator .
The JSON library has the following line (where ObjectType
would be tsl::ordered_map
):
using object_t = ObjectType<StringType,
basic_json,
object_comparator_t,
AllocatorType<std::pair<const StringType, basic_json>>>;
Due to its nature (open-addressing hash map), the tsl::ordered_map
has to store std::pair<Key, T>
instead of std::pair<const Key, T>
as done by std::map
and std::unorderd_map
. It thus needs an AllocatorType<std::pair<StringType, basic_json>>
instead of an AllocatorType<std::pair<const StringType, basic_json>>
. I overlooked that in my reply on the nlohmann/json library and previous versions of GCC didn't have this check.
One way to overcome this would be to ignore the allocator (replace std::allocator
with yours if you don't use the default one):
template<class Key, class T, class Ignore1, class Ignore2, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>, class Allocator = std::allocator<std::pair<Key, T>>>
using ordered_map = tsl::ordered_map<Key, T, Hash, KeyEqual, Allocator>;
I have to check if there is a better way, but this one should works.
Thanks! This works for me! 👍
I updated my reply on the nlohmann/json issue.
It's better to prefer this way so that when a specific allocator is used in nlohmann::json
, it will also be used by tsl::ordered_map
without requiring any change:
template<class Key, class T, class Ignore, class Allocator,
class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>>
using ordered_map = tsl::ordered_map<Key, T, Hash, KeyEqual,
typename std::allocator_traits<Allocator>::template
rebind_alloc<std::pair<Key, T>>>;
WOW! Even better! Thanks a lot! 👍
Using MinGW GCC 8 RC from here. There is the compilation error when using the following code:
This is the following error: