0
Files
src/components/prefs/transparent_unordered_string_map.h
Jan Keitel 562889db3f Introduce TransparentUnorderedStringMap.
The added file contains a simple alias of an std::unordered_map
that supports looking up std::string_view without incurring a copy.

Bug: 349741884
Change-Id: I50ef7faa2a1c04b03d4ea9c3d9bbb26aff2c6b77
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5676786
Reviewed-by: Colin Blundell <blundell@chromium.org>
Commit-Queue: Jan Keitel <jkeitel@google.com>
Reviewed-by: Dominic Battré <battre@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1323590}
2024-07-05 08:34:42 +00:00

29 lines
909 B
C++

// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_PREFS_TRANSPARENT_UNORDERED_STRING_MAP_H_
#define COMPONENTS_PREFS_TRANSPARENT_UNORDERED_STRING_MAP_H_
#include <functional>
#include <string>
#include <string_view>
#include <unordered_map>
namespace internal {
struct StringViewHasher : public std::hash<std::string_view> {
using is_transparent = void;
};
} // namespace internal
// A `std::unordered_map` from `std::string` to `ValueType` that allows
// copy-less find for `std::string_view`.
template <typename ValueType>
using TransparentUnorderedStringMap =
std::unordered_map<std::string,
ValueType,
internal::StringViewHasher,
std::equal_to<>>;
#endif // COMPONENTS_PREFS_TRANSPARENT_UNORDERED_STRING_MAP_H_