Skip to content

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

@clevijoki

Description

@clevijoki

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions