Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
clevijoki opened this issue Sep 2, 2021 · 0 comments

Comments

@clevijoki
Copy link

clevijoki commented Sep 2, 2021

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.

@clevijoki clevijoki changed the title Creation of default values can be incompatible with convertible_to_type structure Creation of default values can be incompatible with convertible_to_value structure Sep 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant