From 8b0bc70db73b48d833a3b5791e55921768cf6932 Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Mon, 31 Mar 2025 08:33:08 -0500 Subject: Remove reinterpret_cast usage in favor of std::bit_cast. --- include/fud_hash_map.hpp | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'include/fud_hash_map.hpp') diff --git a/include/fud_hash_map.hpp b/include/fud_hash_map.hpp index 4333df7..7980bf4 100644 --- a/include/fud_hash_map.hpp +++ b/include/fud_hash_map.hpp @@ -156,8 +156,25 @@ class HashMap { Option extractPair(const Key& key); Option extractPair(Key& key); - Option get(const Key& key) const; - Option getRef(const Key& key); + Option get(const Key& key) + { + auto hashIndexOption = lookup(key); + if (hashIndexOption.isNone()) { + return NullOpt; + } + + return m_data[hashIndexOption.value()].value().m_value; + } + + Option getRef(const Key& key) const + { + auto hashIndexOption = lookup(key); + if (hashIndexOption.isNone()) { + return NullOpt; + } + + return m_data[hashIndexOption.value()].value().m_value; + } Option getConstRef(const Key& key) const { @@ -206,8 +223,7 @@ class HashMap { return dataPtrResult.takeError(); } - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) - auto* dataPtr = reinterpret_cast(dataPtrResult.takeOkay()); + auto* dataPtr = std::bit_cast(dataPtrResult.takeOkay()); for (size_t index = 0; index < count; ++index) { const auto* ptr = new (dataPtr + index) Node(NullOpt); fudAssert(ptr != nullptr); @@ -219,8 +235,7 @@ class HashMap { const auto hash = m_hasher(key, m_seed); auto newHashIndexResult = findEmptyBucket(key, count, dataPtr); if (newHashIndexResult.isError()) { - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) - m_allocator->deallocate(reinterpret_cast(dataPtr), requestedSize); + m_allocator->deallocate(std::bit_cast(dataPtr), requestedSize); return FudStatus::Failure; } const auto newHashIndex{newHashIndexResult.takeOkay()}; @@ -233,8 +248,7 @@ class HashMap { auto status = FudStatus::Success; if (m_buckets > 0) { - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) - m_allocator->deallocate(reinterpret_cast(m_data), m_buckets * NodeSize); + m_allocator->deallocate(std::bit_cast(m_data), m_buckets * NodeSize); } m_data = dataPtr; @@ -295,8 +309,7 @@ class HashMap { { auto status = clear(); if (m_data != nullptr && m_allocator != nullptr) { - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) - m_allocator->deallocate(reinterpret_cast(m_data), m_buckets); + m_allocator->deallocate(std::bit_cast(m_data), m_buckets); } m_allocator = nullptr; -- cgit v1.2.3