From f500c42658c18a04ba0b58739093b465f4f84bee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= Date: Wed, 17 Nov 2021 14:26:17 +0100 Subject: [PATCH] Generalize ArrayProxy and ArrayProxyNoTemporaries constructors Add new constructors that accept any vector-like type (with compatible .data() and .size() methods). Replaces the more specific constructors accepting std::array, std::vector and std::span. --- VulkanHppGenerator.cpp | 206 +++++------------------------------------ 1 file changed, 25 insertions(+), 181 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 9e92d3e..a4e1a63 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -15647,84 +15647,24 @@ int main( int argc, char ** argv ) # pragma GCC diagnostic pop # endif - template - ArrayProxy( std::array const & data ) VULKAN_HPP_NOEXCEPT - : m_count( N ) - , m_ptr( data.data() ) + // Any type with a .data() return type implicitly convertible to T*, and a + // .size() return type implicitly convertible to size_t. The const version + // can capture temporaries, with lifetime ending at end of statement. + template().data()), T*>::value + && std::is_convertible().size()), std::size_t>::value>::type* = nullptr> + ArrayProxy( const V & v ) VULKAN_HPP_NOEXCEPT + : m_count( static_cast( v.size() ) ), + m_ptr( v.data() ) {} - - template ::value, int>::type = 0> - ArrayProxy( std::array::type, N> const & data ) VULKAN_HPP_NOEXCEPT - : m_count( N ) - , m_ptr( data.data() ) + template().data()), T*>::value + && std::is_convertible().size()), std::size_t>::value>::type* = nullptr> + ArrayProxy( V & v ) VULKAN_HPP_NOEXCEPT + : m_count( static_cast( v.size() ) ), + m_ptr( v.data() ) {} - template - ArrayProxy( std::array & data ) VULKAN_HPP_NOEXCEPT - : m_count( N ) - , m_ptr( data.data() ) - {} - - template ::value, int>::type = 0> - ArrayProxy( std::array::type, N> & data ) VULKAN_HPP_NOEXCEPT - : m_count( N ) - , m_ptr( data.data() ) - {} - - template ::type>> - ArrayProxy( std::vector const & data ) VULKAN_HPP_NOEXCEPT - : m_count( static_cast( data.size() ) ) - , m_ptr( data.data() ) - {} - - template ::type>, - typename B = T, - typename std::enable_if::value, int>::type = 0> - ArrayProxy( std::vector::type, Allocator> const & data ) VULKAN_HPP_NOEXCEPT - : m_count( static_cast( data.size() ) ) - , m_ptr( data.data() ) - {} - - template ::type>> - ArrayProxy( std::vector & data ) VULKAN_HPP_NOEXCEPT - : m_count( static_cast( data.size() ) ) - , m_ptr( data.data() ) - {} - - template ::type>, - typename B = T, - typename std::enable_if::value, int>::type = 0> - ArrayProxy( std::vector::type, Allocator> & data ) VULKAN_HPP_NOEXCEPT - : m_count( static_cast( data.size() ) ) - , m_ptr( data.data() ) - {} - -#if defined( VULKAN_HPP_SUPPORT_SPAN ) - template - ArrayProxy( std::span const & data ) VULKAN_HPP_NOEXCEPT - : m_count( static_cast( data.size() ) ) - , m_ptr( data.data() ) - {} - - template ::value, int>::type = 0> - ArrayProxy( std::span::type, N> const & data ) VULKAN_HPP_NOEXCEPT - : m_count( static_cast( data.size() ) ) - , m_ptr( data.data() ) - {} - - template - ArrayProxy( std::span & data ) VULKAN_HPP_NOEXCEPT - : m_count( static_cast( data.size() ) ) - , m_ptr( data.data() ) - {} - - template ::value, int>::type = 0> - ArrayProxy( std::span::type, N> & data ) VULKAN_HPP_NOEXCEPT - : m_count( static_cast( data.size() ) ) - , m_ptr( data.data() ) - {} -#endif - const T * begin() const VULKAN_HPP_NOEXCEPT { return m_ptr; @@ -15786,7 +15726,8 @@ int main( int argc, char ** argv ) , m_ptr( &value ) {} - ArrayProxyNoTemporaries( T && value ) = delete; + template + ArrayProxyNoTemporaries( V && value ) = delete; template ::value, int>::type = 0> ArrayProxyNoTemporaries( typename std::remove_const::type & value ) VULKAN_HPP_NOEXCEPT @@ -15841,113 +15782,16 @@ int main( int argc, char ** argv ) template ::value, int>::type = 0> ArrayProxyNoTemporaries( std::initializer_list::type> && list ) = delete; - template - ArrayProxyNoTemporaries( std::array const & data ) VULKAN_HPP_NOEXCEPT - : m_count( N ) - , m_ptr( data.data() ) + // Any type with a .data() return type implicitly convertible to T*, and a + // .size() return type implicitly convertible to size_t. + template().data()), T*>::value + && std::is_convertible().size()), std::size_t>::value>::type* = nullptr> + ArrayProxyNoTemporaries( V & v ) VULKAN_HPP_NOEXCEPT + : m_count( static_cast( v.size() ) ), + m_ptr( v.data() ) {} - template - ArrayProxyNoTemporaries( std::array const && data ) = delete; - - template ::value, int>::type = 0> - ArrayProxyNoTemporaries( std::array::type, N> const & data ) VULKAN_HPP_NOEXCEPT - : m_count( N ) - , m_ptr( data.data() ) - {} - - template ::value, int>::type = 0> - ArrayProxyNoTemporaries( std::array::type, N> const && data ) = delete; - - template - ArrayProxyNoTemporaries( std::array & data ) VULKAN_HPP_NOEXCEPT - : m_count( N ) - , m_ptr( data.data() ) - {} - - template - ArrayProxyNoTemporaries( std::array && data ) = delete; - - template ::value, int>::type = 0> - ArrayProxyNoTemporaries( std::array::type, N> & data ) VULKAN_HPP_NOEXCEPT - : m_count( N ) - , m_ptr( data.data() ) - {} - - template ::value, int>::type = 0> - ArrayProxyNoTemporaries( std::array::type, N> && data ) = delete; - - template ::type>> - ArrayProxyNoTemporaries( std::vector const & data ) VULKAN_HPP_NOEXCEPT - : m_count( static_cast( data.size() ) ) - , m_ptr( data.data() ) - {} - - template ::type>> - ArrayProxyNoTemporaries( std::vector const && data ) = delete; - - template ::type>, - typename B = T, - typename std::enable_if::value, int>::type = 0> - ArrayProxyNoTemporaries( std::vector::type, Allocator> const & data ) - VULKAN_HPP_NOEXCEPT - : m_count( static_cast( data.size() ) ) - , m_ptr( data.data() ) - {} - - template ::type>, - typename B = T, - typename std::enable_if::value, int>::type = 0> - ArrayProxyNoTemporaries( std::vector::type, Allocator> const && data ) = delete; - - template ::type>> - ArrayProxyNoTemporaries( std::vector & data ) VULKAN_HPP_NOEXCEPT - : m_count( static_cast( data.size() ) ) - , m_ptr( data.data() ) - {} - - template ::type>> - ArrayProxyNoTemporaries( std::vector && data ) = delete; - - template ::type>, - typename B = T, - typename std::enable_if::value, int>::type = 0> - ArrayProxyNoTemporaries( std::vector::type, Allocator> & data ) VULKAN_HPP_NOEXCEPT - : m_count( static_cast( data.size() ) ) - , m_ptr( data.data() ) - {} - - template ::type>, - typename B = T, - typename std::enable_if::value, int>::type = 0> - ArrayProxyNoTemporaries( std::vector::type, Allocator> && data ) = delete; - -#if defined( VULKAN_HPP_SUPPORT_SPAN ) - template - ArrayProxyNoTemporaries( std::span const & data ) VULKAN_HPP_NOEXCEPT - : m_count( static_cast( data.size() ) ) - , m_ptr( data.data() ) - {} - - template ::value, int>::type = 0> - ArrayProxyNoTemporaries( std::span::type, N> const & data ) VULKAN_HPP_NOEXCEPT - : m_count( static_cast( data.size() ) ) - , m_ptr( data.data() ) - {} - - template - ArrayProxyNoTemporaries( std::span & data ) VULKAN_HPP_NOEXCEPT - : m_count( static_cast( data.size() ) ) - , m_ptr( data.data() ) - {} - - template ::value, int>::type = 0> - ArrayProxyNoTemporaries( std::span::type, N> & data ) VULKAN_HPP_NOEXCEPT - : m_count( static_cast( data.size() ) ) - , m_ptr( data.data() ) - {} -#endif - const T * begin() const VULKAN_HPP_NOEXCEPT { return m_ptr;