From 59e3d41305ac76c6709fcd73f7afefb0ae294dde Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Thu, 6 Nov 2025 21:38:09 +0100 Subject: [PATCH] unordered_map heterogeneous access --- client/scenes/stream_tracking.cpp | 2 +- client/xr/instance.h | 7 ++++--- common/utils/strings.h | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/client/scenes/stream_tracking.cpp b/client/scenes/stream_tracking.cpp index deceb93c..5b92a54e 100644 --- a/client/scenes/stream_tracking.cpp +++ b/client/scenes/stream_tracking.cpp @@ -304,7 +304,7 @@ void scenes::stream::tracking() device_id::RIGHT_GRIP, device_id::RIGHT_PALM, }; - if (instance.has_extension("XR_EXT_hand_interaction")) + if (instance.has_extension(XR_EXT_HAND_INTERACTION_EXTENSION_NAME)) { spdlog::info("Adding hand_interaction poses to device list"); ids.insert(ids.end(), {device_id::LEFT_PINCH_POSE, device_id::LEFT_POKE, device_id::RIGHT_PINCH_POSE, device_id::RIGHT_POKE}); diff --git a/client/xr/instance.h b/client/xr/instance.h index 16929299..96efdcb9 100644 --- a/client/xr/instance.h +++ b/client/xr/instance.h @@ -24,6 +24,7 @@ #endif #include "utils/handle.h" +#include "utils/strings.h" #include "xr/check.h" #include #include @@ -49,7 +50,7 @@ class instance : public utils::handle { std::string runtime_version; std::string runtime_name; - std::unordered_map loaded_extensions; + std::unordered_map> loaded_extensions; XrVersion api_version; public: @@ -99,12 +100,12 @@ public: static std::vector extensions(const char * layer_name = nullptr); - bool has_extension(const std::string & extension_name) + bool has_extension(const char * extension_name) { return loaded_extensions.find(extension_name) != loaded_extensions.end(); } - uint32_t extension_version(const std::string & extension_name) + uint32_t extension_version(const char * extension_name) { auto it = loaded_extensions.find(extension_name); if (it != loaded_extensions.end()) diff --git a/common/utils/strings.h b/common/utils/strings.h index e93b9fc4..247039cf 100644 --- a/common/utils/strings.h +++ b/common/utils/strings.h @@ -20,9 +20,29 @@ #pragma once #include +#include #include namespace utils { std::vector split(const std::string & s, const std::string & sep = "\n"); + +// https://www.cppstories.com/2021/heterogeneous-access-cpp20/ +struct string_hash +{ + using is_transparent = void; + [[nodiscard]] size_t operator()(const char * txt) const + { + return std::hash{}(txt); + } + [[nodiscard]] size_t operator()(std::string_view txt) const + { + return std::hash{}(txt); + } + [[nodiscard]] size_t operator()(const std::string & txt) const + { + return std::hash{}(txt); + } +}; + } // namespace utils