Introduce struct hash<vk::Flags<BitType>>

Allows the use of any vk::*Flags type as the key in a std::unordered_map
This commit is contained in:
asuessenbach 2021-07-19 12:12:12 +02:00
parent f70d4291e4
commit 488780dfd4
2 changed files with 21 additions and 1 deletions

View File

@ -409,7 +409,17 @@ std::string VulkanHppGenerator::generateHashStructures() const
${hashes}
)";
std::string hashes;
// start with the hash on Flags<BitType>
std::string hashes = R"(
template <typename BitType> struct hash<VULKAN_HPP_NAMESPACE::Flags<BitType>>
{
std::size_t operator()(VULKAN_HPP_NAMESPACE::Flags<BitType> const& flags) const VULKAN_HPP_NOEXCEPT
{
return std::hash<typename std::underlying_type<BitType>::type>{}(static_cast<typename std::underlying_type<BitType>::type>(flags));
}
};
)";
for ( auto const & feature : m_features )
{
hashes += generateHashStructures( feature.second.types, feature.first );

View File

@ -13263,6 +13263,16 @@ namespace std
//=== HASH structures ===
//=======================
template <typename BitType>
struct hash<VULKAN_HPP_NAMESPACE::Flags<BitType>>
{
std::size_t operator()( VULKAN_HPP_NAMESPACE::Flags<BitType> const & flags ) const VULKAN_HPP_NOEXCEPT
{
return std::hash<typename std::underlying_type<BitType>::type>{}(
static_cast<typename std::underlying_type<BitType>::type>( flags ) );
}
};
//=== VK_VERSION_1_0 ===
template <>