martinus / unordered_dense

A fast & densely stored hashmap and hashset based on robin-hood backward shift deletion
MIT License
898 stars 72 forks source link

can't compiler with T=std::deque<std::unique<T>> #63

Closed yanwei1983 closed 1 year ago

yanwei1983 commented 1 year ago

Describe the bug can't compiler with T=std::deque<std::unique>

To Reproduce

#include "https://raw.githubusercontent.com/martinus/unordered_dense/main/include/ankerl/unordered_dense.h"

#include <deque>
#include <memory>
#include <unordered_map>

using value_t = std::deque<std::unique_ptr<uint32_t>>;
ankerl::unordered_dense::map<uint32_t, value_t> test_map; //compiler error
std::unordered_map<uint32_t, value_t> test_map_std; //succ
martinus commented 1 year ago

Interesting, the problem boils down to this:

using value_t = std::deque<std::unique_ptr<uint32_t>>;
using pair_t = std::pair<uint32_t, value_t>;
auto v = std::vector<pair_t>{};
v.reserve(100); // compile error

So the problem is this doesn't work for a vector with a pair that has a deque with unique_ptr...

martinus commented 1 year ago

I'm sorry, there's nothing I can do here. This seems to be a defect in the C++ stdlib. std::deque is not required that move constructor is noexcept, and for some reason using it as part of a std::pair causes this to fail.

I'm using an std::vector as the base for unordered_map, so this simply can't work.

yanwei1983 commented 1 year ago

i change the value_t , it succ

struct value_t : public std::deque<std::unique_ptr<uint32_t>>
{
    value_t(value_t&&) noexcept = default;
};

thanks

martinus commented 1 year ago

Ha, that's a nice workaround!