From 49d026083b52dd0f79cb46df65510d219bf999c6 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Mon, 19 May 2025 20:38:19 +0000 Subject: [PATCH] Use transparent comparators for `StringMap` and `StringPairs` --- src/libutil/include/nix/util/types.hh | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/libutil/include/nix/util/types.hh b/src/libutil/include/nix/util/types.hh index 5139256ca..edb34f5e2 100644 --- a/src/libutil/include/nix/util/types.hh +++ b/src/libutil/include/nix/util/types.hh @@ -12,8 +12,25 @@ namespace nix { typedef std::list Strings; -typedef std::map StringMap; -typedef std::map StringPairs; + +/** + * Alias to ordered std::string -> std::string map container with transparent comparator. + * + * Used instead of std::map to use C++14 N3657 [1] + * heterogenous lookup consistently across the whole codebase. + * Transparent comparators get rid of creation of unnecessary + * temporary variables when looking up keys by `std::string_view` + * or C-style `const char *` strings. + * + * [1]: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3657.htm + */ +using StringMap = std::map>; +/** + * Alias to an ordered map of std::string -> std::string. Uses transparent comparator. + * + * @see StringMap + */ +using StringPairs = StringMap; /** * Alias to ordered set container with transparent comparator.