template struct StructExtends { enum { value = false }; }; template struct IsPartOfStructureChain { static const bool valid = false; }; template struct IsPartOfStructureChain { static const bool valid = std::is_same::value || IsPartOfStructureChain::valid; }; template struct StructureChainContains { static const bool value = std::is_same>::type>::value || StructureChainContains::value; }; template struct StructureChainContains<0, T, ChainElements...> { static const bool value = std::is_same>::type>::value; }; template struct StructureChainValidation { using TestType = typename std::tuple_element>::type; static const bool valid = StructExtends>::type>::value && ( TestType::allowDuplicate || !StructureChainContains::value ) && StructureChainValidation::valid; }; template struct StructureChainValidation<0, ChainElements...> { static const bool valid = true; }; template class StructureChain : public std::tuple { public: StructureChain() VULKAN_HPP_NOEXCEPT { static_assert( StructureChainValidation::valid, "The structure chain is not valid!" ); link(); } StructureChain( StructureChain const & rhs ) VULKAN_HPP_NOEXCEPT : std::tuple( rhs ) { static_assert( StructureChainValidation::valid, "The structure chain is not valid!" ); link( &std::get<0>( *this ), &std::get<0>( rhs ), reinterpret_cast( &std::get<0>( *this ) ), reinterpret_cast( &std::get<0>( rhs ) ) ); } StructureChain( StructureChain && rhs ) VULKAN_HPP_NOEXCEPT : std::tuple( std::forward>( rhs ) ) { static_assert( StructureChainValidation::valid, "The structure chain is not valid!" ); link( &std::get<0>( *this ), &std::get<0>( rhs ), reinterpret_cast( &std::get<0>( *this ) ), reinterpret_cast( &std::get<0>( rhs ) ) ); } StructureChain( ChainElements const &... elems ) VULKAN_HPP_NOEXCEPT : std::tuple( elems... ) { static_assert( StructureChainValidation::valid, "The structure chain is not valid!" ); link(); } StructureChain & operator=( StructureChain const & rhs ) VULKAN_HPP_NOEXCEPT { std::tuple::operator=( rhs ); link( &std::get<0>( *this ), &std::get<0>( rhs ), reinterpret_cast( &std::get<0>( *this ) ), reinterpret_cast( &std::get<0>( rhs ) ) ); return *this; } StructureChain & operator=( StructureChain && rhs ) = delete; template >::type, size_t Which = 0> T & get() VULKAN_HPP_NOEXCEPT { return std::get::value>( static_cast &>( *this ) ); } template >::type, size_t Which = 0> T const & get() const VULKAN_HPP_NOEXCEPT { return std::get::value>( static_cast const &>( *this ) ); } template std::tuple get() VULKAN_HPP_NOEXCEPT { return std::tie( get(), get(), get()... ); } template std::tuple get() const VULKAN_HPP_NOEXCEPT { return std::tie( get(), get(), get()... ); } template typename std::enable_if< std::is_same>::type>::value && ( Which == 0 ), bool>::type isLinked() const VULKAN_HPP_NOEXCEPT { return true; } template typename std::enable_if< !std::is_same>::type>::value || ( Which != 0 ), bool>::type isLinked() const VULKAN_HPP_NOEXCEPT { static_assert( IsPartOfStructureChain::valid, "Can't unlink Structure that's not part of this StructureChain!" ); return isLinked( reinterpret_cast( &get() ) ); } template typename std::enable_if< !std::is_same>::type>::value || ( Which != 0 ), void>::type relink() VULKAN_HPP_NOEXCEPT { static_assert( IsPartOfStructureChain::valid, "Can't relink Structure that's not part of this StructureChain!" ); auto pNext = reinterpret_cast( &get() ); VULKAN_HPP_ASSERT( !isLinked( pNext ) ); auto & headElement = std::get<0>( static_cast &>( *this ) ); pNext->pNext = reinterpret_cast( headElement.pNext ); headElement.pNext = pNext; } template typename std::enable_if< !std::is_same>::type>::value || ( Which != 0 ), void>::type unlink() VULKAN_HPP_NOEXCEPT { static_assert( IsPartOfStructureChain::valid, "Can't unlink Structure that's not part of this StructureChain!" ); unlink( reinterpret_cast( &get() ) ); } private: template struct ChainElementIndex : ChainElementIndex {}; template struct ChainElementIndex::value, void>::type, First, Types...> : ChainElementIndex {}; template struct ChainElementIndex::value, void>::type, First, Types...> : ChainElementIndex {}; template struct ChainElementIndex::value, void>::type, First, Types...> : std::integral_constant {}; bool isLinked( VkBaseInStructure const * pNext ) const VULKAN_HPP_NOEXCEPT { VkBaseInStructure const * elementPtr = reinterpret_cast( &std::get<0>( static_cast const &>( *this ) ) ); while ( elementPtr ) { if ( elementPtr->pNext == pNext ) { return true; } elementPtr = elementPtr->pNext; } return false; } template typename std::enable_if::type link() VULKAN_HPP_NOEXCEPT { auto & x = std::get( static_cast &>( *this ) ); x.pNext = &std::get( static_cast &>( *this ) ); link(); } template typename std::enable_if::type link() VULKAN_HPP_NOEXCEPT {} void link( void * dstBase, void const * srcBase, VkBaseOutStructure * dst, VkBaseInStructure const * src ) { while ( src->pNext ) { std::ptrdiff_t offset = reinterpret_cast( src->pNext ) - reinterpret_cast( srcBase ); dst->pNext = reinterpret_cast( reinterpret_cast( dstBase ) + offset ); dst = dst->pNext; src = src->pNext; } dst->pNext = nullptr; } void unlink( VkBaseOutStructure const * pNext ) VULKAN_HPP_NOEXCEPT { VkBaseOutStructure * elementPtr = reinterpret_cast( &std::get<0>( static_cast &>( *this ) ) ); while ( elementPtr && ( elementPtr->pNext != pNext ) ) { elementPtr = elementPtr->pNext; } if ( elementPtr ) { elementPtr->pNext = pNext->pNext; } else { VULKAN_HPP_ASSERT( false ); // fires, if the ClassType member has already been unlinked ! } } };