Make StringKeyed* more complete
[folly.git] / folly / experimental / StringKeyedUnorderedMap.h
index 59aa139f496c58b9d03682e7b88a291669fcb075..7099332ab3fc66207e79481b36d7b3df6f5186c0 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.
 
 #pragma once
 
+#include <functional>
 #include <initializer_list>
 #include <memory>
 #include <unordered_map>
+#include <utility>
+
+#include <folly/Hash.h>
 #include <folly/Range.h>
 #include <folly/experimental/StringKeyedCommon.h>
 
@@ -33,13 +37,14 @@ namespace folly {
  * It uses kind of hack: string pointed by StringPiece is copied when
  * StringPiece is inserted into map
  */
-template <class Value,
-          class Hash = StringPieceHash,
-          class Eq = std::equal_to<StringPiece>,
-          class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
+template <
+    class Value,
+    class Hash = Hash,
+    class Eq = std::equal_to<StringPiece>,
+    class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
 class StringKeyedUnorderedMap
     : private std::unordered_map<StringPiece, Value, Hash, Eq, Alloc> {
-private:
+ private:
   using Base = std::unordered_map<StringPiece, Value, Hash, Eq, Alloc>;
 
 public:
@@ -146,11 +151,16 @@ public:
   using Base::cbegin;
   using Base::cend;
 
-  bool operator==(const StringKeyedUnorderedMap& rhs) {
-    const Base& lhs = *this;
+  bool operator==(StringKeyedUnorderedMap const& other) const {
+    Base const& lhs = *this;
+    Base const& rhs = static_cast<Base const&>(other);
     return lhs == rhs;
   }
 
+  void swap(StringKeyedUnorderedMap& other) & {
+    return Base::swap(other);
+  }
+
   // No need for copy/move overload as StringPiece is small struct.
   mapped_type& operator[](StringPiece key) {
     auto it = find(key);
@@ -164,6 +174,7 @@ public:
 
   using Base::at;
   using Base::find;
+  using Base::count;
 
   template <class... Args>
   std::pair<iterator, bool> emplace(StringPiece key, Args&&... args) {