Tessil / sparse-map

C++ implementation of a memory efficient hash map and hash set
MIT License
334 stars 36 forks source link

Template mismatch with std::unordered_map #15

Closed timotejroiko closed 3 years ago

timotejroiko commented 3 years ago

Hello,

Im trying to support both tsl and std in a single class as follows:

template<template<class...> class Container>
class Map {
    private:
        Container<uint64_t, char *> data;
}

// Map<std::unordered_map>()
// Map<tsl::sparse_map>()

However this gives me:

the template parameter list for class template 'tsl::sparse_map' does not match the template parameter list for template parameter

Apparently because of two non-class parameters at the end of tsl's template. Is there a workaround for this? sparse_pg_map works but not sparse_map.

Tessil commented 3 years ago

Hello,

I though that something like:

template<template<auto...> class Container>
class Map {
    private:
        Container<uint64_t, char *> data;
}

would work but it doesn't seem possible.

The only workaround I can think of is:

template<template<class...> class Container>
class Map {
    private:
        Container<uint64_t, char *> data;
}

template <class Key, class T, class Hash = std::hash<Key>,
          class KeyEqual = std::equal_to<Key>,
          class Allocator = std::allocator<std::pair<Key, T>>>
using sparse_map = tsl::sparse_map<Key, T, Hash, KeyEqual, Allocator>;

Map<sparse_map>();

I am not sure if there is a better way to circumvent the problem.

timotejroiko commented 3 years ago

Hello, thanks for the reply!

That's exactly what tried doing but couldn't figure out the correct way to do it, thanks for pointing me in the right direction, everything seems to be working now :)