| 2287 | |
| 2288 | template <typename OtherKey, typename Mapped> |
| 2289 | std::pair<iterator, bool> insertOrAssignImpl(OtherKey&& key, Mapped&& obj) { |
| 2290 | ROBIN_HOOD_TRACE(this) |
| 2291 | auto idxAndState = insertKeyPrepareEmptySpot(key); |
| 2292 | switch (idxAndState.second) { |
| 2293 | case InsertionState::key_found: |
| 2294 | mKeyVals[idxAndState.first].getSecond() = std::forward<Mapped>(obj); |
| 2295 | break; |
| 2296 | |
| 2297 | case InsertionState::new_node: |
| 2298 | ::new (static_cast<void*>(&mKeyVals[idxAndState.first])) Node( |
| 2299 | *this, std::piecewise_construct, std::forward_as_tuple(std::forward<OtherKey>(key)), |
| 2300 | std::forward_as_tuple(std::forward<Mapped>(obj))); |
| 2301 | break; |
| 2302 | |
| 2303 | case InsertionState::overwrite_node: |
| 2304 | mKeyVals[idxAndState.first] = Node(*this, std::piecewise_construct, |
| 2305 | std::forward_as_tuple(std::forward<OtherKey>(key)), |
| 2306 | std::forward_as_tuple(std::forward<Mapped>(obj))); |
| 2307 | break; |
| 2308 | |
| 2309 | case InsertionState::overflow_error: |
| 2310 | throwOverflowError(); |
| 2311 | break; |
| 2312 | } |
| 2313 | |
| 2314 | return std::make_pair(iterator(mKeyVals + idxAndState.first, mInfo + idxAndState.first), |
| 2315 | InsertionState::key_found != idxAndState.second); |
| 2316 | } |
| 2317 | |
| 2318 | void initData(size_t max_elements) { |
| 2319 | mNumElements = 0; |