Add ArrayProxy constructors with support for raw array with size

There's a little known C language family feature, which makes it
possible to take a pointer or reference to an array with size. Use this
feature to add constructors to ArrayProxy and ArrayProxyNoTemporaries
which can wrap raw arrays and deduce their size automatically.
This commit is contained in:
phantom10111 2022-04-15 17:17:44 +02:00
parent 25256d1d59
commit 5df998c0d6
3 changed files with 68 additions and 0 deletions

View File

@ -185,6 +185,10 @@ c.setScissor(0, scissorRect);
// pass a temporary value. // pass a temporary value.
c.setScissor(0, { { 0, 0 },{ 640, 480 } }); c.setScissor(0, { { 0, 0 },{ 640, 480 } });
// pass a fixed size array
vk::Rect2D scissorRects[2] = { { { 0, 0 }, { 320, 240 } }, { { 320, 240 }, { 320, 240 } } };
c.setScissor(0, scissorRects);
// generate a std::initializer_list using two rectangles from the stack. This might generate a copy of the rectangles. // generate a std::initializer_list using two rectangles from the stack. This might generate a copy of the rectangles.
vk::Rect2D scissorRect1 = { { 0, 0 },{ 320, 240 } }; vk::Rect2D scissorRect1 = { { 0, 0 },{ 320, 240 } };
vk::Rect2D scissorRect2 = { { 320, 240 },{ 320, 240 } }; vk::Rect2D scissorRect2 = { { 320, 240 },{ 320, 240 } };

View File

@ -14851,6 +14851,18 @@ int main( int argc, char ** argv )
, m_ptr( ptr ) , m_ptr( ptr )
{} {}
template <std::size_t C>
ArrayProxy( T (& 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>
ArrayProxy( typename std::remove_const<T>::type (& ptr)[C] ) VULKAN_HPP_NOEXCEPT
: m_count( C )
, m_ptr( ptr )
{}
# if __GNUC__ >= 9 # if __GNUC__ >= 9
# pragma GCC diagnostic push # pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Winit-list-lifetime" # pragma GCC diagnostic ignored "-Winit-list-lifetime"
@ -14986,6 +14998,24 @@ int main( int argc, char ** argv )
, m_ptr( ptr ) , m_ptr( ptr )
{} {}
template <std::size_t C>
ArrayProxyNoTemporaries( T (& ptr)[C] ) VULKAN_HPP_NOEXCEPT
: m_count( C )
, m_ptr( ptr )
{}
template <std::size_t C>
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 ArrayProxyNoTemporaries( std::initializer_list<T> const & list ) VULKAN_HPP_NOEXCEPT
: m_count( static_cast<uint32_t>( list.size() ) ) : m_count( static_cast<uint32_t>( list.size() ) )
, m_ptr( list.begin() ) , m_ptr( list.begin() )

View File

@ -283,6 +283,20 @@ namespace VULKAN_HPP_NAMESPACE
{ {
} }
template <std::size_t C>
ArrayProxy( T ( &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>
ArrayProxy( typename std::remove_const<T>::type ( &ptr )[C] ) VULKAN_HPP_NOEXCEPT
: m_count( C )
, m_ptr( ptr )
{
}
# if __GNUC__ >= 9 # if __GNUC__ >= 9
# pragma GCC diagnostic push # pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Winit-list-lifetime" # pragma GCC diagnostic ignored "-Winit-list-lifetime"
@ -428,6 +442,26 @@ namespace VULKAN_HPP_NAMESPACE
{ {
} }
template <std::size_t C>
ArrayProxyNoTemporaries( T ( &ptr )[C] ) VULKAN_HPP_NOEXCEPT
: m_count( C )
, m_ptr( ptr )
{
}
template <std::size_t C>
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 ArrayProxyNoTemporaries( std::initializer_list<T> const & list ) VULKAN_HPP_NOEXCEPT
: m_count( static_cast<uint32_t>( list.size() ) ) : m_count( static_cast<uint32_t>( list.size() ) )
, m_ptr( list.begin() ) , m_ptr( list.begin() )