From f4a8b0434ad2e2945def09afff0bd8a5da4d6d72 Mon Sep 17 00:00:00 2001 From: Anqi Dong Date: Fri, 15 Jul 2022 19:26:50 +0000 Subject: [PATCH] flat_map: Avoid double-templating Pair As is, the type is a bit obnoxious to name, because you have to use either FlatMap::Pair or FlatMap::value_type. Because FlatMap doesn't have any copy semantics, you are pretty much required to use constructors that take the expected std::array, should a class want to decorate this type. Change-Id: I908fdf7d0f4502932d2c1244e8e8b5dc593267a8 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/102130 Commit-Queue: Anqi Dong Reviewed-by: Armando Montanez --- pw_containers/public/pw_containers/flat_map.h | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pw_containers/public/pw_containers/flat_map.h b/pw_containers/public/pw_containers/flat_map.h index 9df709ffb3..3027a0e53f 100644 --- a/pw_containers/public/pw_containers/flat_map.h +++ b/pw_containers/public/pw_containers/flat_map.h @@ -21,9 +21,18 @@ namespace pw::containers { +// Define and use a custom Pair object. This is because std::pair does not +// support constexpr assignment until C++20. The assignment is needed since +// the array of pairs will be sorted in the constructor (if not already). +template +struct Pair { + First first; + Second second; +}; + // A simple, fixed-size associative array with lookup by key or value. // -// FlatMaps are initialized with a std::array of FlatMap::Pair objects: +// FlatMaps are initialized with a std::array of Pair objects: // FlatMap map({{{1, 2}, {3, 4}}}); // // The keys do not need to be sorted as the constructor will sort the items @@ -31,15 +40,6 @@ namespace pw::containers { template class FlatMap { public: - // Define and use a custom Pair object. This is because std::pair does not - // support constexpr assignment until C++20. The assignment is needed since - // the array of pairs will be sorted in the constructor (if not already). - template - struct Pair { - First first; - Second second; - }; - using key_type = Key; using mapped_type = Value; using value_type = Pair;