#include <folly/Hash.h>
#include <folly/ThreadCachedInt.h>
+#include <folly/Utility.h>
namespace folly {
// Enables specializing checkLegalKey without specializing its class.
namespace detail {
-// Local copy of folly::gen::Identity, to avoid heavy dependencies.
-class AHAIdentity {
- public:
- template<class Value>
- auto operator()(Value&& value) const ->
- decltype(std::forward<Value>(value)) {
- return std::forward<Value>(value);
- }
-};
-
template <typename NotKeyT, typename KeyT>
inline void checkLegalKeyIfKeyTImpl(NotKeyT /* ignored */,
KeyT /* emptyKey */,
}
} // namespace detail
-template <class KeyT, class ValueT,
- class HashFcn = std::hash<KeyT>,
- class EqualFcn = std::equal_to<KeyT>,
- class Allocator = std::allocator<char>,
- class ProbeFcn = AtomicHashArrayLinearProbeFcn,
- class KeyConvertFcn = detail::AHAIdentity>
+template <
+ class KeyT,
+ class ValueT,
+ class HashFcn = std::hash<KeyT>,
+ class EqualFcn = std::equal_to<KeyT>,
+ class Allocator = std::allocator<char>,
+ class ProbeFcn = AtomicHashArrayLinearProbeFcn,
+ class KeyConvertFcn = Identity>
class AtomicHashMap;
-template <class KeyT, class ValueT,
- class HashFcn = std::hash<KeyT>,
- class EqualFcn = std::equal_to<KeyT>,
- class Allocator = std::allocator<char>,
- class ProbeFcn = AtomicHashArrayLinearProbeFcn,
- class KeyConvertFcn = detail::AHAIdentity>
+template <
+ class KeyT,
+ class ValueT,
+ class HashFcn = std::hash<KeyT>,
+ class EqualFcn = std::equal_to<KeyT>,
+ class Allocator = std::allocator<char>,
+ class ProbeFcn = AtomicHashArrayLinearProbeFcn,
+ class KeyConvertFcn = Identity>
class AtomicHashArray : boost::noncopyable {
static_assert((std::is_convertible<KeyT,int32_t>::value ||
std::is_convertible<KeyT,int64_t>::value ||
SimpleRetT() = default;
};
-
-
- template <typename LookupKeyT = key_type,
- typename LookupHashFcn = hasher,
- typename LookupEqualFcn = key_equal,
- typename LookupKeyToKeyFcn = detail::AHAIdentity,
- typename... ArgTs>
+ template <
+ typename LookupKeyT = key_type,
+ typename LookupHashFcn = hasher,
+ typename LookupEqualFcn = key_equal,
+ typename LookupKeyToKeyFcn = Identity,
+ typename... ArgTs>
SimpleRetT insertInternal(LookupKeyT key, ArgTs&&... vCtorArgs);
template <typename LookupKeyT = key_type,
using make_index_sequence = detail::make_index_sequence<N>;
#endif
+
+/**
+ * A simple function object that passes its argument through unchanged.
+ *
+ * Example:
+ *
+ * int i = 42;
+ * int &j = Identity()(i);
+ * assert(&i == &j);
+ *
+ * Warning: passing a prvalue through Identity turns it into an xvalue,
+ * which can effect whether lifetime extension occurs or not. For instance:
+ *
+ * auto&& x = std::make_unique<int>(42);
+ * cout << *x ; // OK, x refers to a valid unique_ptr.
+ *
+ * auto&& y = Identity()(std::make_unique<int>(42));
+ * cout << *y ; // ERROR: y did not lifetime-extend the unique_ptr. It
+ * // is no longer valid
+ */
+struct Identity {
+ using is_transparent = void;
+ template <class T>
+ constexpr T&& operator()(T&& x) const noexcept {
+ return static_cast<T&&>(x);
+ }
+};
}