Flat map all the things

In an earlier commit, entity-manager gained required dependency
on std::flat_map.  This means that EM can only compile with gcc-15,
which the project only recently moved to.  Rather than move backwards,
port forward all uses of boost flat_map and flat_set to their std
equivalents.

Tested: entity-manager launches and enumerates devices on
gb200-obmc.

Change-Id: Id24803057711c60d5b00f436db80b27edbb756a3
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/src/fru_device/fru_device.cpp b/src/fru_device/fru_device.cpp
index 3d806a2..304cb0b 100644
--- a/src/fru_device/fru_device.cpp
+++ b/src/fru_device/fru_device.cpp
@@ -10,7 +10,6 @@
 
 #include <boost/asio/io_context.hpp>
 #include <boost/asio/steady_timer.hpp>
-#include <boost/container/flat_map.hpp>
 #include <nlohmann/json.hpp>
 #include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/asio/connection.hpp>
@@ -22,6 +21,8 @@
 #include <chrono>
 #include <ctime>
 #include <filesystem>
+#include <flat_map>
+#include <flat_set>
 #include <fstream>
 #include <functional>
 #include <future>
@@ -60,16 +61,15 @@
 
 // TODO Refactor these to not be globals
 // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)
-static boost::container::flat_map<size_t, std::optional<std::set<size_t>>>
-    busBlocklist;
+static std::flat_map<size_t, std::optional<std::flat_set<size_t>>> busBlocklist;
 struct FindDevicesWithCallback;
 
-static boost::container::flat_map<
-    std::pair<size_t, size_t>, std::shared_ptr<sdbusplus::asio::dbus_interface>>
+static std::flat_map<std::pair<size_t, size_t>,
+                     std::shared_ptr<sdbusplus::asio::dbus_interface>>
     foundDevices;
 
-static boost::container::flat_map<size_t, std::set<size_t>> failedAddresses;
-static boost::container::flat_map<size_t, std::set<size_t>> fruAddresses;
+static std::flat_map<size_t, std::flat_set<size_t>> failedAddresses;
+static std::flat_map<size_t, std::flat_set<size_t>> fruAddresses;
 
 boost::asio::io_context io;
 // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)
@@ -77,9 +77,9 @@
 bool updateFruProperty(
     const std::string& propertyValue, uint32_t bus, uint32_t address,
     const std::string& propertyName,
-    boost::container::flat_map<
-        std::pair<size_t, size_t>,
-        std::shared_ptr<sdbusplus::asio::dbus_interface>>& dbusInterfaceMap,
+    std::flat_map<std::pair<size_t, size_t>,
+                  std::shared_ptr<sdbusplus::asio::dbus_interface>>&
+        dbusInterfaceMap,
     size_t& unknownBusObjectCount, const bool& powerIsOn,
     const std::set<size_t>& addressBlocklist,
     sdbusplus::asio::object_server& objServer);
@@ -454,8 +454,8 @@
 
         // Scan for i2c eeproms loaded on this bus.
         std::set<size_t> skipList = findI2CEeproms(bus, devices);
-        std::set<size_t>& failedItems = failedAddresses[bus];
-        std::set<size_t>& foundItems = fruAddresses[bus];
+        std::flat_set<size_t>& failedItems = failedAddresses[bus];
+        std::flat_set<size_t>& foundItems = fruAddresses[bus];
         foundItems.clear();
 
         skipList.insert_range(addressBlocklist);
@@ -472,7 +472,7 @@
             }
         }
 
-        std::set<size_t>* rootFailures = nullptr;
+        std::flat_set<size_t>* rootFailures = nullptr;
         int rootBus = getRootBus(bus);
 
         if (rootBus >= 0)
@@ -875,14 +875,14 @@
 
 void addFruObjectToDbus(
     std::vector<uint8_t>& device,
-    boost::container::flat_map<
-        std::pair<size_t, size_t>,
-        std::shared_ptr<sdbusplus::asio::dbus_interface>>& dbusInterfaceMap,
+    std::flat_map<std::pair<size_t, size_t>,
+                  std::shared_ptr<sdbusplus::asio::dbus_interface>>&
+        dbusInterfaceMap,
     uint32_t bus, uint32_t address, size_t& unknownBusObjectCount,
     const bool& powerIsOn, const std::set<size_t>& addressBlocklist,
     sdbusplus::asio::object_server& objServer)
 {
-    boost::container::flat_map<std::string, std::string> formattedFRU;
+    std::flat_map<std::string, std::string, std::less<>> formattedFRU;
 
     std::optional<std::string> optionalProductName = getProductName(
         device, formattedFRU, bus, address, unknownBusObjectCount);
@@ -928,7 +928,7 @@
             });
     }
 
-    for (auto& property : formattedFRU)
+    for (auto property : formattedFRU)
     {
         std::regex_replace(property.second.begin(), property.second.begin(),
                            property.second.end(), nonAsciiRegex, "_");
@@ -1005,7 +1005,7 @@
 
 bool writeFRU(uint8_t bus, uint8_t address, const std::vector<uint8_t>& fru)
 {
-    boost::container::flat_map<std::string, std::string> tmp;
+    std::flat_map<std::string, std::string, std::less<>> tmp;
     if (fru.size() > maxFruSize)
     {
         lg2::error("Invalid fru.size() during writeFRU");
@@ -1146,9 +1146,9 @@
 
 void rescanOneBus(
     BusMap& busmap, uint16_t busNum,
-    boost::container::flat_map<
-        std::pair<size_t, size_t>,
-        std::shared_ptr<sdbusplus::asio::dbus_interface>>& dbusInterfaceMap,
+    std::flat_map<std::pair<size_t, size_t>,
+                  std::shared_ptr<sdbusplus::asio::dbus_interface>>&
+        dbusInterfaceMap,
     bool dbusCall, size_t& unknownBusObjectCount, const bool& powerIsOn,
     const std::set<size_t>& addressBlocklist,
     sdbusplus::asio::object_server& objServer)
@@ -1203,7 +1203,7 @@
             {
                 return;
             }
-            for (auto& device : *(found->second))
+            for (auto device : *(found->second))
             {
                 addFruObjectToDbus(device.second, dbusInterfaceMap,
                                    static_cast<uint32_t>(busNum), device.first,
@@ -1216,9 +1216,9 @@
 
 void rescanBusses(
     BusMap& busmap,
-    boost::container::flat_map<
-        std::pair<size_t, size_t>,
-        std::shared_ptr<sdbusplus::asio::dbus_interface>>& dbusInterfaceMap,
+    std::flat_map<std::pair<size_t, size_t>,
+                  std::shared_ptr<sdbusplus::asio::dbus_interface>>&
+        dbusInterfaceMap,
     size_t& unknownBusObjectCount, const bool& powerIsOn,
     const std::set<size_t>& addressBlocklist,
     sdbusplus::asio::object_server& objServer)
@@ -1242,7 +1242,7 @@
         auto devDir = fs::path("/dev/");
         std::vector<fs::path> i2cBuses;
 
-        boost::container::flat_map<size_t, fs::path> busPaths;
+        std::flat_map<size_t, fs::path> busPaths;
         if (!getI2cDevicePaths(devDir, busPaths))
         {
             lg2::error("unable to find i2c devices");
@@ -1255,7 +1255,7 @@
         }
 
         busmap.clear();
-        for (auto& [pair, interface] : foundDevices)
+        for (auto [pair, interface] : foundDevices)
         {
             objServer.remove_interface(interface);
         }
@@ -1263,7 +1263,7 @@
 
         auto scan = std::make_shared<FindDevicesWithCallback>(
             i2cBuses, busmap, powerIsOn, objServer, addressBlocklist, [&]() {
-                for (auto& busIface : dbusInterfaceMap)
+                for (auto busIface : dbusInterfaceMap)
                 {
                     objServer.remove_interface(busIface.second);
                 }
@@ -1280,9 +1280,9 @@
                         busmap.try_emplace(0, std::make_shared<DeviceMap>());
                     bus0.first->second->emplace(0, baseboardFRU);
                 }
-                for (auto& devicemap : busmap)
+                for (auto devicemap : busmap)
                 {
-                    for (auto& device : *devicemap.second)
+                    for (auto device : *devicemap.second)
                     {
                         addFruObjectToDbus(device.second, dbusInterfaceMap,
                                            devicemap.first, device.first,
@@ -1298,9 +1298,9 @@
 bool updateFruProperty(
     const std::string& propertyValue, uint32_t bus, uint32_t address,
     const std::string& propertyName,
-    boost::container::flat_map<
-        std::pair<size_t, size_t>,
-        std::shared_ptr<sdbusplus::asio::dbus_interface>>& dbusInterfaceMap,
+    std::flat_map<std::pair<size_t, size_t>,
+                  std::shared_ptr<sdbusplus::asio::dbus_interface>>&
+        dbusInterfaceMap,
     size_t& unknownBusObjectCount, const bool& powerIsOn,
     const std::set<size_t>& addressBlocklist,
     sdbusplus::asio::object_server& objServer)
@@ -1364,8 +1364,8 @@
 
     // this is a map with keys of pair(bus number, address) and values of
     // the object on dbus
-    boost::container::flat_map<std::pair<size_t, size_t>,
-                               std::shared_ptr<sdbusplus::asio::dbus_interface>>
+    std::flat_map<std::pair<size_t, size_t>,
+                  std::shared_ptr<sdbusplus::asio::dbus_interface>>
         dbusInterfaceMap;
 
     std::shared_ptr<sdbusplus::asio::dbus_interface> iface =
@@ -1401,9 +1401,8 @@
     std::function<void(sdbusplus::message_t & message)> eventHandler =
         [&](sdbusplus::message_t& message) {
             std::string objectName;
-            boost::container::flat_map<
-                std::string,
-                std::variant<std::string, bool, int64_t, uint64_t, double>>
+            std::flat_map<std::string, std::variant<std::string, bool, int64_t,
+                                                    uint64_t, double>>
                 values;
             message.read(objectName, values);
             auto findState = values.find("CurrentHostState");
diff --git a/src/fru_device/fru_utils.cpp b/src/fru_device/fru_utils.cpp
index efb4ec1..1efcd30 100644
--- a/src/fru_device/fru_utils.cpp
+++ b/src/fru_device/fru_utils.cpp
@@ -277,7 +277,7 @@
 
 static void parseMultirecordUUID(
     std::span<const uint8_t> device,
-    boost::container::flat_map<std::string, std::string>& result)
+    std::flat_map<std::string, std::string, std::less<>>& result)
 {
     constexpr size_t uuidDataLen = 16;
     constexpr size_t multiRecordHeaderLen = 5;
@@ -364,7 +364,7 @@
     std::span<const uint8_t>::const_iterator& fruBytesIterEndArea,
     const std::vector<std::string>& fruAreaFieldNames, size_t& fieldIndex,
     DecodeState& state, bool isLangEng, const fruAreas& area,
-    boost::container::flat_map<std::string, std::string>& result)
+    std::flat_map<std::string, std::string, std::less<>>& result)
 {
     auto res = decodeFRUData(fruBytesIter, fruBytesIterEndArea, isLangEng);
     state = res.first;
@@ -432,7 +432,7 @@
 
 resCodes formatIPMIFRU(
     std::span<const uint8_t> fruBytes,
-    boost::container::flat_map<std::string, std::string>& result)
+    std::flat_map<std::string, std::string, std::less<>>& result)
 {
     resCodes ret = resCodes::resOK;
     if (fruBytes.size() <= fruBlockSize)
@@ -1594,9 +1594,9 @@
 // regular expression and find the device index for all devices.
 
 std::optional<int> findIndexForFRU(
-    boost::container::flat_map<
-        std::pair<size_t, size_t>,
-        std::shared_ptr<sdbusplus::asio::dbus_interface>>& dbusInterfaceMap,
+    std::flat_map<std::pair<size_t, size_t>,
+                  std::shared_ptr<sdbusplus::asio::dbus_interface>>&
+        dbusInterfaceMap,
     std::string& productName)
 {
     int highest = -1;
@@ -1640,7 +1640,7 @@
 
 std::optional<std::string> getProductName(
     std::vector<uint8_t>& device,
-    boost::container::flat_map<std::string, std::string>& formattedFRU,
+    std::flat_map<std::string, std::string, std::less<>>& formattedFRU,
     uint32_t bus, uint32_t address, size_t& unknownBusObjectCount)
 {
     std::string productName;
diff --git a/src/fru_device/fru_utils.hpp b/src/fru_device/fru_utils.hpp
index d689d5c..1465a9d 100644
--- a/src/fru_device/fru_utils.hpp
+++ b/src/fru_device/fru_utils.hpp
@@ -4,11 +4,11 @@
 #pragma once
 #include "fru_reader.hpp"
 
-#include <boost/container/flat_map.hpp>
 #include <sdbusplus/asio/object_server.hpp>
 
 #include <cstdint>
 #include <cstdio>
+#include <flat_map>
 #include <functional>
 #include <regex>
 #include <string>
@@ -22,8 +22,8 @@
 
 constexpr size_t fruBlockSize = 8;
 
-using DeviceMap = boost::container::flat_map<int, std::vector<uint8_t>>;
-using BusMap = boost::container::flat_map<int, std::shared_ptr<DeviceMap>>;
+using DeviceMap = std::flat_map<int, std::vector<uint8_t>>;
+using BusMap = std::flat_map<int, std::shared_ptr<DeviceMap>>;
 
 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
 inline BusMap busMap;
@@ -111,7 +111,7 @@
 
 resCodes formatIPMIFRU(
     std::span<const uint8_t> fruBytes,
-    boost::container::flat_map<std::string, std::string>& result);
+    std::flat_map<std::string, std::string, std::less<>>& result);
 
 std::vector<uint8_t>& getFRUInfo(const uint16_t& bus, const uint8_t& address);
 
@@ -198,9 +198,9 @@
 /// \return optional<int> highest index for fru device on success, return
 /// nullopt on failure.
 std::optional<int> findIndexForFRU(
-    boost::container::flat_map<
-        std::pair<size_t, size_t>,
-        std::shared_ptr<sdbusplus::asio::dbus_interface>>& dbusInterfaceMap,
+    std::flat_map<std::pair<size_t, size_t>,
+                  std::shared_ptr<sdbusplus::asio::dbus_interface>>&
+        dbusInterfaceMap,
     std::string& productName);
 
 /// \brief It does format fru data and find productName in the formatted
@@ -214,7 +214,7 @@
 
 std::optional<std::string> getProductName(
     std::vector<uint8_t>& device,
-    boost::container::flat_map<std::string, std::string>& formattedFRU,
+    std::flat_map<std::string, std::string, std::less<>>& formattedFRU,
     uint32_t bus, uint32_t address, size_t& unknownBusObjectCount);
 
 bool getFruData(std::vector<uint8_t>& fruData, uint32_t bus, uint32_t address);