Add streaming API
[folly.git] / folly / AtomicHashArray-inl.h
index 84b01ef307d7da8661e85a210c7da9f280249704..d2cb08f460718ed651079f4c3bc47c52253d2b53 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -31,7 +31,7 @@ template <class KeyT, class ValueT, class HashFcn, class EqualFcn,
 AtomicHashArray<KeyT, ValueT, HashFcn, EqualFcn,
                 Allocator, ProbeFcn, KeyConvertFcn>::
 AtomicHashArray(size_t capacity, KeyT emptyKey, KeyT lockedKey,
-                KeyT erasedKey, double _maxLoadFactor, size_t cacheSize)
+                KeyT erasedKey, double _maxLoadFactor, uint32_t cacheSize)
     : capacity_(capacity),
       maxEntries_(size_t(_maxLoadFactor * capacity_ + 0.5)),
       kEmptyKey_(emptyKey), kLockedKey_(lockedKey), kErasedKey_(erasedKey),
@@ -152,7 +152,11 @@ insertInternal(LookupKeyT key_in, ArgTs&&... vCtorArgs) {
               checkLegalKeyIfKey(key_new);
             }
             DCHECK(relaxedLoadKey(*cell) == kLockedKey_);
-            new (&cell->second) ValueT(std::forward<ArgTs>(vCtorArgs)...);
+            // A const mapped_type is only constant once constructed, so cast
+            // away any const for the placement new here.
+            using mapped = typename std::remove_const<mapped_type>::type;
+            new (const_cast<mapped*>(&cell->second))
+                ValueT(std::forward<ArgTs>(vCtorArgs)...);
             unlockCell(cell, key_new); // Sets the new key
           } catch (...) {
             // Transition back to empty key---requires handling