From 488780dfd4c7a06ce02963391e33b12d32447208 Mon Sep 17 00:00:00 2001 From: asuessenbach Date: Mon, 19 Jul 2021 12:12:12 +0200 Subject: [PATCH] Introduce struct hash> Allows the use of any vk::*Flags type as the key in a std::unordered_map --- VulkanHppGenerator.cpp | 12 +++++++++++- vulkan/vulkan.hpp | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index b805def..94169e9 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -409,7 +409,17 @@ std::string VulkanHppGenerator::generateHashStructures() const ${hashes} )"; - std::string hashes; + // start with the hash on Flags + std::string hashes = R"( + template struct hash> + { + std::size_t operator()(VULKAN_HPP_NAMESPACE::Flags const& flags) const VULKAN_HPP_NOEXCEPT + { + return std::hash::type>{}(static_cast::type>(flags)); + } + }; +)"; + for ( auto const & feature : m_features ) { hashes += generateHashStructures( feature.second.types, feature.first ); diff --git a/vulkan/vulkan.hpp b/vulkan/vulkan.hpp index 7c130a6..a1164f4 100644 --- a/vulkan/vulkan.hpp +++ b/vulkan/vulkan.hpp @@ -13263,6 +13263,16 @@ namespace std //=== HASH structures === //======================= + template + struct hash> + { + std::size_t operator()( VULKAN_HPP_NAMESPACE::Flags const & flags ) const VULKAN_HPP_NOEXCEPT + { + return std::hash::type>{}( + static_cast::type>( flags ) ); + } + }; + //=== VK_VERSION_1_0 === template <>