Skip to content

Commit

Permalink
Add specializations of std::tuple_element and std::tuple_size for vk:…
Browse files Browse the repository at this point in the history
…:StructureChain.
  • Loading branch information
asuessenbach committed Jun 22, 2023
1 parent 13808e5 commit 68cb6b1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
20 changes: 20 additions & 0 deletions snippets/StructureChain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,23 @@
}
}
};
// interupt the VULKAN_HPP_NAMESPACE for a moment to add specializations of std::tuple_size and std::tuple_element for the StructureChain!
}

namespace std
{
template <typename... Elements>
struct tuple_size<VULKAN_HPP_NAMESPACE::StructureChain<Elements...>>
{
static constexpr size_t value = std::tuple_size_v<std::tuple<Elements...>>;
};

template <std::size_t Index, typename... Elements>
struct tuple_element<Index, VULKAN_HPP_NAMESPACE::StructureChain<Elements...>>
{
using type = std::tuple_element_t<Index, std::tuple<Elements...>>;
};
} // namespace std

namespace VULKAN_HPP_NAMESPACE
{
10 changes: 8 additions & 2 deletions tests/StructureChain/StructureChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,19 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::PhysicalDevicePushDescriptorPropertiesKHR>
sc7;

#if !defined(NDEBUG)
#if ( 17 <= VULKAN_HPP_CPP_VERSION )
// test for structured binding from a StructureChain
auto const & [p0, p1] = sc1;
auto & [p2, p3] = sc2;
#endif

#if !defined( NDEBUG )
void * pNext = sc7.get<vk::PhysicalDeviceIDProperties>().pNext;
#endif
sc7.assign<vk::PhysicalDeviceIDProperties>( {} );
assert( pNext == sc7.get<vk::PhysicalDeviceIDProperties>().pNext );

#if !defined(NDEBUG)
#if !defined( NDEBUG )
void * pNext1 = sc7.get<vk::PhysicalDeviceMaintenance3Properties>().pNext;
#endif
sc7.assign<vk::PhysicalDeviceMaintenance3Properties>( {} ).assign<vk::PhysicalDeviceIDProperties>( {} );
Expand Down
21 changes: 21 additions & 0 deletions vulkan/vulkan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,27 @@ namespace VULKAN_HPP_NAMESPACE
}
};

// interupt the VULKAN_HPP_NAMESPACE for a moment to add specializations of std::tuple_size and std::tuple_element for the StructureChain!
}

namespace std
{
template <typename... Elements>
struct tuple_size<VULKAN_HPP_NAMESPACE::StructureChain<Elements...>>
{
static constexpr size_t value = std::tuple_size_v<std::tuple<Elements...>>;
};

template <std::size_t Index, typename... Elements>
struct tuple_element<Index, VULKAN_HPP_NAMESPACE::StructureChain<Elements...>>
{
using type = std::tuple_element_t<Index, std::tuple<Elements...>>;
};
} // namespace std

namespace VULKAN_HPP_NAMESPACE
{

# if !defined( VULKAN_HPP_NO_SMART_HANDLE )
template <typename Type, typename Dispatch>
class UniqueHandleTraits;
Expand Down

0 comments on commit 68cb6b1

Please sign in to comment.