1 // Copyright 2024 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef COMPONENTS_PREFS_TRANSPARENT_UNORDERED_STRING_MAP_H_ 6 #define COMPONENTS_PREFS_TRANSPARENT_UNORDERED_STRING_MAP_H_ 7 8 #include <functional> 9 #include <string> 10 #include <string_view> 11 #include <unordered_map> 12 13 namespace internal { 14 struct StringViewHasher : public std::hash<std::string_view> { 15 using is_transparent = void; 16 }; 17 } // namespace internal 18 19 // A `std::unordered_map` from `std::string` to `ValueType` that allows 20 // copy-less find for `std::string_view`. 21 template <typename ValueType> 22 using TransparentUnorderedStringMap = 23 std::unordered_map<std::string, 24 ValueType, 25 internal::StringViewHasher, 26 std::equal_to<>>; 27 28 #endif // COMPONENTS_PREFS_TRANSPARENT_UNORDERED_STRING_MAP_H_ 29