This is essentially a follow up to my earlier question Difference between std::unordered_map < K, boost::ptr_deque < T > >'s operator[] (K const &) and emplace
I am trying to implement a associative vector (call it unordered_flat_map) and would like to support operator [key]
Here is the code...
#include <utility>
#include <tuple>
#include <vector>
struct T
{
T() = default;
T(T const &) = delete;
T & operator = (T const &) = delete;
T(T &&) = delete;
T & operator = (T &&) = delete;
};
using S = T;
int main()
{
using value_type = std::pair < uint32_t, S >;
std::vector < value_type > testuvm;
value_type p(std::piecewise_construct, std::forward_as_tuple(2), std::forward_as_tuple());
// testuvm.emplace_back(std::piecewise_construct, std::forward_as_tuple(2), std::forward_as_tuple());
}
The commented out line fails to compile, which is what unordered_map::operator []
does if the key is not found. Is there a way to make this work? If not, why is this not possible? Is this due to a limitation of vector
?