Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: compiled/StringMap.h

Issue 29676717: Noissue - Make the key a template parameter for Map<> (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Jan. 22, 2018, 4:31 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiled/StringMap.h
===================================================================
--- a/compiled/StringMap.h
+++ b/compiled/StringMap.h
@@ -19,19 +19,21 @@
#include <cstddef>
#include "Map.h"
#include "String.h"
namespace StringMap_internal
{
+ template<typename Key,
+ class = typename std::enable_if<std::is_base_of<String, Key>::value>::type>
struct StringSetEntry
{
- typedef DependentString key_type;
+ typedef Key key_type;
typedef const String& key_type_cref;
typedef size_t size_type;
key_type first;
StringSetEntry(key_type_cref key = key_type())
{
if (!key.is_invalid())
@@ -63,34 +65,36 @@
// FNV-1a hash function
size_type result = 2166136261;
for (String::size_type i = 0; i < key.length(); i++)
result = (result ^ key[i]) * 16777619;
return result;
}
};
- template<typename Value>
- struct StringMapEntry : StringSetEntry
+ template<typename Key, typename Value>
+ struct StringMapEntry : StringSetEntry<Key>
{
- typedef StringSetEntry super;
+ typedef StringSetEntry<Key> super;
typedef Value value_type;
value_type second;
- StringMapEntry(key_type_cref key = DependentString(),
+ StringMapEntry(typename super::key_type_cref key = Key(),
value_type value = value_type())
: super(key), second(value)
{
}
void erase()
{
super::erase();
second = value_type();
}
};
}
-using StringSet = Set<StringMap_internal::StringSetEntry>;
+using StringSet = Set<StringMap_internal::StringSetEntry<DependentString>>;
template<typename Value>
-using StringMap = Map<StringMap_internal::StringMapEntry<Value>>;
+using StringMap = Map<StringMap_internal::StringMapEntry<DependentString, Value>>;
+template<typename Value>
+using OwnedStringMap = Map<StringMap_internal::StringMapEntry<OwnedString, Value>>;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld