|
|
|||
File indexing completed on 2026-09-15 09:18:32
0001 #ifndef PODIO_UTILITIES_STRINGKEYMAP_H 0002 #define PODIO_UTILITIES_STRINGKEYMAP_H 0003 0004 #include <functional> 0005 #include <string> 0006 #include <string_view> 0007 #include <unordered_map> 0008 0009 namespace podio { 0010 0011 namespace detail { 0012 0013 /// Transparent hash for @c std::string keyed @c std::unordered_map that enables 0014 /// heterogeneous lookup with @c std::string_view (and @c const @c char*) without 0015 /// constructing a temporary @c std::string for each lookup. Must be used together 0016 /// with @c std::equal_to<> as the key equality comparator so that the same 0017 /// key-comparison transparency applies. 0018 struct TransparentStringHash { 0019 using is_transparent = void; 0020 // We only need the string_View overload because a string converts to that 0021 std::size_t operator()(std::string_view sv) const noexcept { 0022 return std::hash<std::string_view>{}(sv); 0023 } 0024 }; 0025 0026 } // namespace detail 0027 0028 /// A convenience alias for @c std::unordered_map<std::string, Value> that 0029 /// supports heterogeneous lookup. 0030 /// 0031 /// Keys can be looked up (via @c find, @c count, @c contains, ...) using any 0032 /// type that is implicitly convertible to @c std::string_view — most notably 0033 /// @c std::string_view and plain string literals — without constructing a 0034 /// temporary @c std::string. This is achieved by pairing @c 0035 /// podio::detail::TransparentStringHash with @c std::equal_to<> (the 0036 /// "transparent" equality comparator introduced in C++14). 0037 /// 0038 /// @note Insertion operations (@c try_emplace, @c operator[], …) still require 0039 /// a @c std::string key since that is the map's @c key_type. Pass 0040 /// @c std::string(sv) explicitly when inserting from a @c std::string_view. 0041 template <typename Value> 0042 using StringKeyMap = std::unordered_map<std::string, Value, detail::TransparentStringHash, std::equal_to<>>; 0043 } // namespace podio 0044 0045 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|