skarupke / flat_hash_map

A very fast hashtable
1.69k stars 186 forks source link

Creation of default values can be incompatible with convertible_to_value structure #42

Open clevijoki opened 2 years ago

clevijoki commented 2 years ago

This code will not compile (in MSVC 2019 or clang 12)

#include <string>
#include <ska_flat_hash_map.hpp>

struct Value
{
    std::string val;
    Value() {}
    template<typename T> Value(const T& t) : val(std::to_string(t)) {}
};

int main(int, char**)
{
    ska::flat_hash_map<int, Value> m;
    m[10] = 42;

    return 0;
}

What ends up happening is internally it routes through the templated constructor and std::to_string<ska::flat_hash_map<int,Value,ska::detailv3::IntegerIdentityHash,std::equal_to<int>,std::allocator<std::pair<int,Value>>>::convertible_to_value> tries to be called, which does not compile.

perhaps instead of using the conversion operator, an explicit default construct call can happen instead, ensuring the empty constructor is called.