X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Fexperimental%2FStringKeyedUnorderedMap.h;h=4cf33b434fa3f292255282020703bbe2d0cd27d7;hb=66a77ad13be358dd2a3f50303586b0297d4637ee;hp=846caa03da7e63d3576f09724e0c1e01a34fdadd;hpb=a1614feea3f3c0beb75fb2dc43ec45b3e5d57223;p=folly.git diff --git a/folly/experimental/StringKeyedUnorderedMap.h b/folly/experimental/StringKeyedUnorderedMap.h index 846caa03..4cf33b43 100644 --- a/folly/experimental/StringKeyedUnorderedMap.h +++ b/folly/experimental/StringKeyedUnorderedMap.h @@ -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. @@ -16,14 +16,17 @@ // Copyright 2013-present Facebook. All Rights Reserved. // @author: Pavlo Kushnir (pavlo) -#ifndef FOLLY_EXPERIMENTAL_STRINGKEYEDUNORDEREDMAP_H_ -#define FOLLY_EXPERIMENTAL_STRINGKEYEDUNORDEREDMAP_H_ +#pragma once +#include #include #include #include +#include + #include #include +#include namespace folly { @@ -34,16 +37,17 @@ namespace folly { * It uses kind of hack: string pointed by StringPiece is copied when * StringPiece is inserted into map */ -template , - class Alloc = std::allocator>> +template < + class Value, + class Hash = Hash, + class Eq = std::equal_to, + class Alloc = std::allocator>> class StringKeyedUnorderedMap : private std::unordered_map { -private: + private: using Base = std::unordered_map; -public: + public: typedef typename Base::key_type key_type; typedef typename Base::mapped_type mapped_type; typedef typename Base::value_type value_type; @@ -147,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(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); @@ -165,6 +174,7 @@ public: using Base::at; using Base::find; + using Base::count; template std::pair emplace(StringPiece key, Args&&... args) { @@ -226,6 +236,4 @@ public: } }; -} // folly - -#endif /* FOLLY_EXPERIMENTAL_STRINGKEYEDUNORDEREDMAP_H_ */ +} // namespace folly