Skip to content

Commit

Permalink
Simplify helper class vk::ArrayProxyNoTemporaries.
Browse files Browse the repository at this point in the history
  • Loading branch information
asuessenbach committed Jun 25, 2024
1 parent 6604f5a commit ed63eba
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 1,082 deletions.
8 changes: 6 additions & 2 deletions VulkanHppGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3300,7 +3300,8 @@ std::string VulkanHppGenerator::generateCallSequence( std::string const &
}
else
{
std::string const callSequenceTemplate = R"(VULKAN_HPP_NAMESPACE::Result result = static_cast<VULKAN_HPP_NAMESPACE::Result>( ${dispatcher}${vkCommand}( ${firstCallArguments} ) );
std::string const callSequenceTemplate =
R"(VULKAN_HPP_NAMESPACE::Result result = static_cast<VULKAN_HPP_NAMESPACE::Result>( ${dispatcher}${vkCommand}( ${firstCallArguments} ) );
if ( result == VULKAN_HPP_NAMESPACE::Result::eSuccess )
{
${resizes}
Expand Down Expand Up @@ -10855,7 +10856,10 @@ std::string VulkanHppGenerator::generateStructConstructors( std::pair<std::strin
{ "initializers", generateList( initializers, ": ", ", " ) },
{ "structName", stripPrefix( structData.first, "Vk" ) } } );

str += generateStructConstructorsEnhanced( structData );
if ( !structData.second.returnedOnly )
{
str += generateStructConstructorsEnhanced( structData );
}
return str;
}

Expand Down
107 changes: 33 additions & 74 deletions snippets/ArrayProxyNoTemporaries.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,101 +5,60 @@
VULKAN_HPP_CONSTEXPR ArrayProxyNoTemporaries() VULKAN_HPP_NOEXCEPT
: m_count( 0 )
, m_ptr( nullptr )
{}
{
}

VULKAN_HPP_CONSTEXPR ArrayProxyNoTemporaries( std::nullptr_t ) VULKAN_HPP_NOEXCEPT
: m_count( 0 )
, m_ptr( nullptr )
{}

ArrayProxyNoTemporaries( T & value ) VULKAN_HPP_NOEXCEPT
: m_count( 1 )
, m_ptr( &value )
{}

template <typename V>
ArrayProxyNoTemporaries( V && value ) = delete;
{
}

template <typename B = T, typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxyNoTemporaries( typename std::remove_const<T>::type & value ) VULKAN_HPP_NOEXCEPT
template <typename B = T, typename std::enable_if<std::is_convertible<B, T>::value && std::is_lvalue_reference<B>::value, int>::type = 0>
ArrayProxyNoTemporaries( B && value ) VULKAN_HPP_NOEXCEPT
: m_count( 1 )
, m_ptr( &value )
{}

template <typename B = T, typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxyNoTemporaries( typename std::remove_const<T>::type && value ) = delete;
{
}

ArrayProxyNoTemporaries( uint32_t count, T * ptr ) VULKAN_HPP_NOEXCEPT
: m_count( count )
, m_ptr( ptr )
{}

template <typename B = T, typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxyNoTemporaries( uint32_t count, typename std::remove_const<T>::type * ptr ) VULKAN_HPP_NOEXCEPT
: m_count( count )
, m_ptr( ptr )
{}
{
}

template <std::size_t C>
ArrayProxyNoTemporaries( T (& ptr)[C] ) VULKAN_HPP_NOEXCEPT
ArrayProxyNoTemporaries( T ( &ptr )[C] ) VULKAN_HPP_NOEXCEPT
: m_count( C )
, m_ptr( ptr )
{}
{
}

template <std::size_t C>
ArrayProxyNoTemporaries( T (&& ptr)[C] ) = delete;
ArrayProxyNoTemporaries( T ( &&ptr )[C] ) = delete;

template <std::size_t C, typename B = T, typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxyNoTemporaries( typename std::remove_const<T>::type (& ptr)[C] ) VULKAN_HPP_NOEXCEPT
: m_count( C )
, m_ptr( ptr )
{}

template <std::size_t C, typename B = T, typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxyNoTemporaries( typename std::remove_const<T>::type (&& ptr)[C] ) = delete;

ArrayProxyNoTemporaries( std::initializer_list<T> const & list ) VULKAN_HPP_NOEXCEPT
: m_count( static_cast<uint32_t>( list.size() ) )
, m_ptr( list.begin() )
{}

ArrayProxyNoTemporaries( std::initializer_list<T> const && list ) = delete;

template <typename B = T, typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxyNoTemporaries( std::initializer_list<typename std::remove_const<T>::type> const & list )
VULKAN_HPP_NOEXCEPT
: m_count( static_cast<uint32_t>( list.size() ) )
, m_ptr( list.begin() )
{}

template <typename B = T, typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxyNoTemporaries( std::initializer_list<typename std::remove_const<T>::type> const && list ) = delete;

ArrayProxyNoTemporaries( std::initializer_list<T> & list ) VULKAN_HPP_NOEXCEPT
: m_count( static_cast<uint32_t>( list.size() ) )
, m_ptr( list.begin() )
{}

ArrayProxyNoTemporaries( std::initializer_list<T> && list ) = delete;

template <typename B = T, typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxyNoTemporaries( std::initializer_list<typename std::remove_const<T>::type> & list ) VULKAN_HPP_NOEXCEPT
: m_count( static_cast<uint32_t>( list.size() ) )
, m_ptr( list.begin() )
{}

template <typename B = T, typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxyNoTemporaries( std::initializer_list<typename std::remove_const<T>::type> && list ) = delete;

// Any type with a .data() return type implicitly convertible to T*, and a .size() return type implicitly convertible to size_t.
// Any l-value reference with a .data() return type implicitly convertible to T*, and a .size() return type implicitly convertible to size_t.
template <typename V,
typename std::enable_if<
std::is_convertible<decltype( std::declval<V>().data() ), T *>::value &&
std::is_convertible<decltype( std::declval<V>().size() ), std::size_t>::value>::type * = nullptr>
ArrayProxyNoTemporaries( V & v ) VULKAN_HPP_NOEXCEPT
typename std::enable_if<!std::is_convertible<decltype( std::declval<V>().begin() ), T *>::value &&
std::is_convertible<decltype( std::declval<V>().data() ), T *>::value &&
std::is_convertible<decltype( std::declval<V>().size() ), std::size_t>::value && std::is_lvalue_reference<V>::value,
int>::type = 0>
ArrayProxyNoTemporaries( V && v ) VULKAN_HPP_NOEXCEPT
: m_count( static_cast<uint32_t>( v.size() ) )
, m_ptr( v.data() )
{}
{
}

// Any l-value reference with a .begin() return type implicitly convertible to T*, and a .size() return type implicitly convertible to size_t.
template <typename V,
typename std::enable_if<std::is_convertible<decltype( std::declval<V>().begin() ), T *>::value &&
std::is_convertible<decltype( std::declval<V>().size() ), std::size_t>::value && std::is_lvalue_reference<V>::value,
int>::type = 0>
ArrayProxyNoTemporaries( V && v ) VULKAN_HPP_NOEXCEPT
: m_count( static_cast<uint32_t>( v.size() ) )
, m_ptr( v.begin() )
{
}

const T * begin() const VULKAN_HPP_NOEXCEPT
{
Expand Down
Loading

0 comments on commit ed63eba

Please sign in to comment.