libchromeos: Added GetMapKeysAsVector() and unit tests

Added chromeos::GetMapKeysAsVector() helper function to obtain
the map as a vector<> instead of a set<>. Also added unit tests
for the map_utils.

BUG=None
TEST=FEATURES=test emerge-link libchromeos buffet

Change-Id: I689a3b0e2c2ddcb532101a5d0750aa789eb2bbda
Reviewed-on: https://chromium-review.googlesource.com/235714
Tested-by: Alex Vakulenko <[email protected]>
Reviewed-by: Christopher Wiley <[email protected]>
Commit-Queue: Alex Vakulenko <[email protected]>
diff --git a/chromeos/map_utils.h b/chromeos/map_utils.h
index 00751a8..031ca73 100644
--- a/chromeos/map_utils.h
+++ b/chromeos/map_utils.h
@@ -21,6 +21,17 @@
   return keys;
 }
 
+// Given an STL map, returns a vector containing all keys from the map.
+// The keys in the vector are sorted.
+template<typename T>
+inline std::vector<typename T::key_type> GetMapKeysAsVector(const T& map) {
+  std::vector<typename T::key_type> keys;
+  keys.reserve(map.size());
+  for (const auto& pair : map)
+    keys.push_back(pair.first);
+  return keys;
+}
+
 // Given an STL map, returns a vector containing all values from the map.
 template<typename T>
 inline std::vector<typename T::mapped_type> GetMapValues(const T& map) {