Split get_default() into two for deferred default construction and added forwarding...
[folly.git] / folly / experimental / StringKeyedMap.h
index 5b33a727c06fa054d85313929d9e60d4ad3d2bab..8c2c1ed6cbf49084e1cdfeeafd19e32d688fb216 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2015 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.
 // Copyright 2013-present Facebook. All Rights Reserved.
 // @author: Pavlo Kushnir (pavlo)
 
-#ifndef FOLLY_EXPERIMENTAL_STRINGKEYEDMAP_H_
-#define FOLLY_EXPERIMENTAL_STRINGKEYEDMAP_H_
+#pragma once
 
 #include <initializer_list>
-#include <memory>
 #include <map>
+#include <memory>
+
 #include <folly/Range.h>
 #include <folly/experimental/StringKeyedCommon.h>
 
@@ -34,15 +34,16 @@ namespace folly {
  * It uses kind of hack: string pointed by StringPiece is copied when
  * StringPiece is inserted into map
  */
-template <class Value,
-          class Compare = std::less<StringPiece>,
-          class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
+template <
+    class Value,
+    class Compare = std::less<StringPiece>,
+    class Alloc = std::allocator<std::pair<const StringPiece, Value>>>
 class StringKeyedMap
     : private std::map<StringPiece, Value, Compare, Alloc> {
-private:
+ private:
   using Base = std::map<StringPiece, Value, Compare, Alloc>;
 
-public:
+ public:
   typedef typename Base::key_type key_type;
   typedef typename Base::mapped_type mapped_type;
   typedef typename Base::value_type value_type;
@@ -97,9 +98,8 @@ public:
     : Base(std::move(other)) {
   }
 
-  StringKeyedMap(StringKeyedMap&& other, const allocator_type& a) noexcept
-      : Base(std::move(other)/*, a*/ /* not supported by gcc */) {
-  }
+  StringKeyedMap(StringKeyedMap&& other, const allocator_type& /* a */) noexcept
+      : Base(std::move(other) /*, a*/ /* not supported by gcc */) {}
 
   StringKeyedMap(std::initializer_list<value_type> il,
      const key_compare& comp = key_compare(),
@@ -133,6 +133,12 @@ public:
   using Base::crbegin;
   using Base::crend;
 
+  bool operator==(StringKeyedMap const& other) const {
+    Base const& lhs = *this;
+    Base const& rhs = static_cast<Base const&>(other);
+    return lhs == rhs;
+  }
+
   // no need for copy/move overload as StringPiece is small struct
   mapped_type& operator[](StringPiece key) {
     auto it = find(key);
@@ -146,6 +152,7 @@ public:
 
   using Base::at;
   using Base::find;
+  using Base::count;
   using Base::lower_bound;
   using Base::upper_bound;
 
@@ -192,6 +199,10 @@ public:
     Base::clear();
   }
 
+  void swap(StringKeyedMap& other) & {
+    return Base::swap(other);
+  }
+
   ~StringKeyedMap() {
     // Here we assume that map doesn't use keys in destructor
     for (auto& it : *this) {
@@ -200,6 +211,4 @@ public:
   }
 };
 
-} // folly
-
-#endif /* FOLLY_EXPERIMENTAL_STRINGKEYEDMAP_H_ */
+} // namespace folly