Introduce constructors of ArrayProxy and ArrayProxyNoTemporaries from std::span (C++20)

This commit is contained in:
asuessenbach 2021-08-04 11:47:42 +02:00
parent 0957f3a3f1
commit af80b7aee8
3 changed files with 217 additions and 75 deletions

View File

@ -15124,6 +15124,32 @@ int main( int argc, char ** argv )
, m_ptr( data.data() ) , m_ptr( data.data() )
{} {}
#if defined( VULKAN_HPP_SUPPORT_SPAN )
template <size_t N = std::dynamic_extent>
ArrayProxy( std::span<T, N> const & data ) VULKAN_HPP_NOEXCEPT
: m_count( static_cast<uint32_t>( data.size() ) )
, m_ptr( data.data() )
{}
template <size_t N = std::dynamic_extent, typename B = T, typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxy( std::span<typename std::remove_const<T>::type, N> const & data ) VULKAN_HPP_NOEXCEPT
: m_count( static_cast<uint32_t>( data.size() ) )
, m_ptr( data.data() )
{}
template <size_t N = std::dynamic_extent>
ArrayProxy( std::span<T, N> & data ) VULKAN_HPP_NOEXCEPT
: m_count( static_cast<uint32_t>( data.size() ) )
, m_ptr( data.data() )
{}
template <size_t N = std::dynamic_extent, typename B = T, typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxy( std::span<typename std::remove_const<T>::type, N> & data ) VULKAN_HPP_NOEXCEPT
: m_count( static_cast<uint32_t>( data.size() ) )
, m_ptr( data.data() )
{}
#endif
const T * begin() const VULKAN_HPP_NOEXCEPT const T * begin() const VULKAN_HPP_NOEXCEPT
{ {
return m_ptr; return m_ptr;
@ -15321,6 +15347,32 @@ int main( int argc, char ** argv )
typename std::enable_if<std::is_const<B>::value, int>::type = 0> typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxyNoTemporaries( std::vector<typename std::remove_const<T>::type, Allocator> && data ) = delete; ArrayProxyNoTemporaries( std::vector<typename std::remove_const<T>::type, Allocator> && data ) = delete;
#if defined( VULKAN_HPP_SUPPORT_SPAN )
template <size_t N = std::dynamic_extent>
ArrayProxyNoTemporaries( std::span<T, N> const & data ) VULKAN_HPP_NOEXCEPT
: m_count( static_cast<uint32_t>( data.size() ) )
, m_ptr( data.data() )
{}
template <size_t N = std::dynamic_extent, typename B = T, typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxyNoTemporaries( std::span<typename std::remove_const<T>::type, N> const & data ) VULKAN_HPP_NOEXCEPT
: m_count( static_cast<uint32_t>( data.size() ) )
, m_ptr( data.data() )
{}
template <size_t N = std::dynamic_extent>
ArrayProxyNoTemporaries( std::span<T, N> & data ) VULKAN_HPP_NOEXCEPT
: m_count( static_cast<uint32_t>( data.size() ) )
, m_ptr( data.data() )
{}
template <size_t N = std::dynamic_extent, typename B = T, typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxyNoTemporaries( std::span<typename std::remove_const<T>::type, N> & data ) VULKAN_HPP_NOEXCEPT
: m_count( static_cast<uint32_t>( data.size() ) )
, m_ptr( data.data() )
{}
#endif
const T * begin() const VULKAN_HPP_NOEXCEPT const T * begin() const VULKAN_HPP_NOEXCEPT
{ {
return m_ptr; return m_ptr;
@ -16670,7 +16722,6 @@ int main( int argc, char ** argv )
#include <tuple> #include <tuple>
#include <type_traits> #include <type_traits>
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#if 17 <= VULKAN_HPP_CPP_VERSION #if 17 <= VULKAN_HPP_CPP_VERSION
# include <string_view> # include <string_view>
#endif #endif
@ -16742,6 +16793,11 @@ extern "C" __declspec( dllimport ) FARPROC __stdcall GetProcAddress( HINSTANCE h
# include <compare> # include <compare>
#endif #endif
#if ( 201803 <= __cpp_lib_span )
# define VULKAN_HPP_SUPPORT_SPAN
# include <span>
#endif
)"; )";
static const std::string structResultValue = R"( static const std::string structResultValue = R"(

View File

@ -16,153 +16,175 @@
// Compile test on using vk::ArrayProxy // Compile test on using vk::ArrayProxy
#include "vulkan/vulkan.hpp" #include "vulkan/vulkan.hpp"
#include <iostream> #include <iostream>
#if ( 20 <= VULKAN_HPP_CPP_VERSION )
# include <span>
#endif
void fct(vk::ArrayProxy<int> /*ap*/) void fct( vk::ArrayProxy<int> /*ap*/ ) {}
{}
void fctc(vk::ArrayProxy<const int> /*ap*/) void fctc( vk::ArrayProxy<const int> /*ap*/ ) {}
{}
int main(int /*argc*/, char ** /*argv*/) int main( int /*argc*/, char ** /*argv*/ )
{ {
try try
{ {
// nullptr_t // nullptr_t
fct(nullptr); fct( nullptr );
fctc(nullptr); fctc( nullptr );
vk::ArrayProxy<int> ap0 = nullptr; vk::ArrayProxy<int> ap0 = nullptr;
assert(ap0.size() == 0); assert( ap0.size() == 0 );
// Type // Type
//fct(2); // not supported: cannot convert from 'const int *' to 'T *' // fct(2); // not supported: cannot convert from 'const int *' to 'T *'
fctc(1); fctc( 1 );
int i0 = 1; int i0 = 1;
fct(i0); fct( i0 );
fctc(i0); fctc( i0 );
const int i1 = 2; const int i1 = 2;
//fct(i1); // not supported: cannot convert from 'const int *' to 'T *' // fct(i1); // not supported: cannot convert from 'const int *' to 'T *'
fctc(i1); fctc( i1 );
// count, T * // count, T *
int* i0p = &i0; int * i0p = &i0;
fct({ 1, i0p }); fct( { 1, i0p } );
fctc({ 1, i0p }); fctc( { 1, i0p } );
// count, T const* // count, T const*
int const* i1p = &i1; int const * i1p = &i1;
//fct({ 1, i1p }); // not supported: cannot convert from 'const int *' to 'T *' // fct({ 1, i1p }); // not supported: cannot convert from 'const int *' to 'T *'
fctc({ 1, i1p }); fctc( { 1, i1p } );
// std::array<T,N> // std::array<T,N>
std::array<int, 2> sa0 = { 0, 1 }; std::array<int, 2> sa0 = { 0, 1 };
fct(sa0); fct( sa0 );
fctc(sa0); fctc( sa0 );
// std::array<T,N> const // std::array<T,N> const
std::array<const int, 2> sa1 = { 0, 1 }; std::array<const int, 2> sa1 = { 0, 1 };
//fct(sa1); // not supported: cannot convert from '_Ty *' to 'T *' // fct(sa1); // not supported: cannot convert from '_Ty *' to 'T *'
fctc(sa1); fctc( sa1 );
std::array<int, 2> const sa2 = { 1, 2 }; std::array<int, 2> const sa2 = { 1, 2 };
//fct(sa2); // not supported: cannot convert from 'const _Ty *' to 'T *' // fct(sa2); // not supported: cannot convert from 'const _Ty *' to 'T *'
fctc(sa2); fctc( sa2 );
std::array<const int, 2> const sa3 = { 1, 2 }; std::array<const int, 2> const sa3 = { 1, 2 };
//fct(sa3); // not supported: cannot convert from '_Ty *' to 'T *' // fct(sa3); // not supported: cannot convert from '_Ty *' to 'T *'
fctc(sa3); fctc( sa3 );
vk::ArrayProxy<int> ap2 = sa0; vk::ArrayProxy<int> ap2 = sa0;
assert(ap2.size() == 2); assert( ap2.size() == 2 );
//vk::ArrayProxy<int> ap3 = sa1; // not supported: cannot convert from '_Ty *' to 'T *' // vk::ArrayProxy<int> ap3 = sa1; // not supported: cannot convert from '_Ty *' to 'T *'
//vk::ArrayProxy<int> ap4 = sa2; // not supported: cannot convert from '_Ty *' to 'T *' // vk::ArrayProxy<int> ap4 = sa2; // not supported: cannot convert from '_Ty *' to 'T *'
//vk::ArrayProxy<int> ap5 = sa3; // not supported: cannot convert from '_Ty *' to 'T *' // vk::ArrayProxy<int> ap5 = sa3; // not supported: cannot convert from '_Ty *' to 'T *'
vk::ArrayProxy<const int> ap6 = sa0; vk::ArrayProxy<const int> ap6 = sa0;
assert(ap6.size() == 2); assert( ap6.size() == 2 );
vk::ArrayProxy<const int> ap7 = sa1; vk::ArrayProxy<const int> ap7 = sa1;
assert(ap7.size() == 2); assert( ap7.size() == 2 );
vk::ArrayProxy<const int> ap8 = sa2; vk::ArrayProxy<const int> ap8 = sa2;
assert(ap8.size() == 2); assert( ap8.size() == 2 );
vk::ArrayProxy<const int> ap9 = sa3; vk::ArrayProxy<const int> ap9 = sa3;
assert(ap9.size() == 2); assert( ap9.size() == 2 );
// std::vector<T> // std::vector<T>
std::vector<int> sv0 = { 0, 1 }; std::vector<int> sv0 = { 0, 1 };
fct(sv0); fct( sv0 );
fctc(sv0); fctc( sv0 );
std::vector<int> const sv1 = { 0, 1 }; std::vector<int> const sv1 = { 0, 1 };
//fct(sv1); // not supported: cannot convert from 'const _Ty *' to 'T *' // fct(sv1); // not supported: cannot convert from 'const _Ty *' to 'T *'
fctc(sv1); fctc( sv1 );
vk::ArrayProxy<int> ap10 = sv0; vk::ArrayProxy<int> ap10 = sv0;
assert(ap10.size() == 2); assert( ap10.size() == 2 );
//vk::ArrayProxy<int> ap11 = sv1; // not supported: cannot convert from '_Ty *' to 'T *' // vk::ArrayProxy<int> ap11 = sv1; // not supported: cannot convert from '_Ty *' to 'T *'
vk::ArrayProxy<const int> ap12 = sv0; vk::ArrayProxy<const int> ap12 = sv0;
assert(ap12.size() == 2); assert( ap12.size() == 2 );
vk::ArrayProxy<const int> ap13 = sv1; vk::ArrayProxy<const int> ap13 = sv1;
assert(ap13.size() == 2); assert( ap13.size() == 2 );
// std::initializer_list // std::initializer_list
fct({}); fct( {} );
fctc({}); fctc( {} );
//fct({ 0, 1 }); // not supported: cannot convert from 'const _Elem *' to 'T *' // fct({ 0, 1 }); // not supported: cannot convert from 'const _Elem *' to 'T *'
fctc({ 0, 1 }); fctc( { 0, 1 } );
int a = 0; int a = 0;
int b = 1; int b = 1;
//fct({ a, b }); // not supported: cannot convert from 'const _Elem *' to 'T *' // fct({ a, b }); // not supported: cannot convert from 'const _Elem *' to 'T *'
fctc({ a,b }); fctc( { a, b } );
auto il0 = { 0, 1 }; // -> std::initializer_list<int> auto il0 = { 0, 1 }; // -> std::initializer_list<int>
//fct(il0); // not supported: cannot convert from 'const _Elem *' to 'T *' // fct(il0); // not supported: cannot convert from 'const _Elem *' to 'T *'
fctc(il0); fctc( il0 );
std::initializer_list<int> il1 = { 0, 1 }; std::initializer_list<int> il1 = { 0, 1 };
//fct(il1); // not supported: cannot convert from 'const _Elem *' to 'T *' // fct(il1); // not supported: cannot convert from 'const _Elem *' to 'T *'
fctc(il1); fctc( il1 );
std::initializer_list<const int> il2 = { 0, 1 }; std::initializer_list<const int> il2 = { 0, 1 };
//fct(il2); // not supported: cannot convert from '_Elem *' to 'T *' // fct(il2); // not supported: cannot convert from '_Elem *' to 'T *'
fctc(il2); fctc( il2 );
std::initializer_list<int> const il3 = { 0, 1 }; std::initializer_list<int> const il3 = { 0, 1 };
//fct(il3); // not supported: cannot convert from 'const _Elem *' to 'T *' // fct(il3); // not supported: cannot convert from 'const _Elem *' to 'T *'
fctc(il3); fctc( il3 );
std::initializer_list<const int> const il4 = { 0, 1 }; std::initializer_list<const int> const il4 = { 0, 1 };
//fct(il4); // not supported: cannot convert from 'const _Elem *' to 'T *' // fct(il4); // not supported: cannot convert from 'const _Elem *' to 'T *'
fctc(il4); fctc( il4 );
//vk::ArrayProxy<int> ap14 = il1; // not supported: cannot convert from 'const _Elem *' to 'T *' // vk::ArrayProxy<int> ap14 = il1; // not supported: cannot convert from 'const _Elem *' to 'T *'
//vk::ArrayProxy<int> ap15 = il2; // not supported: cannot convert from '_Ty *' to 'T *' // vk::ArrayProxy<int> ap15 = il2; // not supported: cannot convert from '_Ty *' to 'T *'
//vk::ArrayProxy<int> ap16 = il3; // not supported: cannot convert from '_Ty *' to 'T *' // vk::ArrayProxy<int> ap16 = il3; // not supported: cannot convert from '_Ty *' to 'T *'
//vk::ArrayProxy<int> ap17 = il4; // not supported: cannot convert from '_Ty *' to 'T *' // vk::ArrayProxy<int> ap17 = il4; // not supported: cannot convert from '_Ty *' to 'T *'
vk::ArrayProxy<const int> ap18 = il1; vk::ArrayProxy<const int> ap18 = il1;
assert(ap18.size() == 2); assert( ap18.size() == 2 );
vk::ArrayProxy<const int> ap19 = il2; vk::ArrayProxy<const int> ap19 = il2;
assert(ap19.size() == 2); assert( ap19.size() == 2 );
vk::ArrayProxy<const int> ap20 = il3; vk::ArrayProxy<const int> ap20 = il3;
assert(ap20.size() == 2); assert( ap20.size() == 2 );
vk::ArrayProxy<const int> ap21 = il4; vk::ArrayProxy<const int> ap21 = il4;
assert(ap21.size() == 2); assert( ap21.size() == 2 );
#if defined( VULKAN_HPP_SUPPORT_SPAN )
// std::span<T, N>
std::span<int> ss0( sa0.begin(), sa0.size() );
fct( ss0 );
fctc( ss0 );
// std::span<T,N> const
std::span<const int> ss1( sa1.begin(), sa1.size() );
// fct(ss1); // not supported: cannot convert from 'std::span<const int>' to 'vk::ArrayProxy<int>'
fctc( ss1 );
std::span<int> const ss2;
fct( ss2 );
fctc( ss2 );
std::span<const int> const ss3( sa3.begin(), sa3.end() );
// fct(ss3); // not supported: cannot convert from 'const std::span<const int>' to 'vk::ArrayProxy<int>'
fctc( ss3 );
#endif
} }
catch (vk::SystemError const& err) catch ( vk::SystemError const & err )
{ {
std::cout << "vk::SystemError: " << err.what() << std::endl; std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1); exit( -1 );
} }
catch (...) catch ( ... )
{ {
std::cout << "unknown error\n"; std::cout << "unknown error\n";
exit(-1); exit( -1 );
} }
return 0; return 0;

View File

@ -39,7 +39,6 @@
#include <tuple> #include <tuple>
#include <type_traits> #include <type_traits>
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#if 17 <= VULKAN_HPP_CPP_VERSION #if 17 <= VULKAN_HPP_CPP_VERSION
# include <string_view> # include <string_view>
#endif #endif
@ -111,6 +110,11 @@ extern "C" __declspec( dllimport ) FARPROC __stdcall GetProcAddress( HINSTANCE h
# include <compare> # include <compare>
#endif #endif
#if ( 201803 <= __cpp_lib_span )
# define VULKAN_HPP_SUPPORT_SPAN
# include <span>
#endif
static_assert( VK_HEADER_VERSION == 187, "Wrong VK_HEADER_VERSION!" ); static_assert( VK_HEADER_VERSION == 187, "Wrong VK_HEADER_VERSION!" );
// 32-bit vulkan is not typesafe for handles, so don't allow copy constructors on this platform by default. // 32-bit vulkan is not typesafe for handles, so don't allow copy constructors on this platform by default.
@ -352,6 +356,36 @@ namespace VULKAN_HPP_NAMESPACE
, m_ptr( data.data() ) , m_ptr( data.data() )
{} {}
# if defined( VULKAN_HPP_SUPPORT_SPAN )
template <size_t N = std::dynamic_extent>
ArrayProxy( std::span<T, N> const & data ) VULKAN_HPP_NOEXCEPT
: m_count( static_cast<uint32_t>( data.size() ) )
, m_ptr( data.data() )
{}
template <size_t N = std::dynamic_extent,
typename B = T,
typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxy( std::span<typename std::remove_const<T>::type, N> const & data ) VULKAN_HPP_NOEXCEPT
: m_count( static_cast<uint32_t>( data.size() ) )
, m_ptr( data.data() )
{}
template <size_t N = std::dynamic_extent>
ArrayProxy( std::span<T, N> & data ) VULKAN_HPP_NOEXCEPT
: m_count( static_cast<uint32_t>( data.size() ) )
, m_ptr( data.data() )
{}
template <size_t N = std::dynamic_extent,
typename B = T,
typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxy( std::span<typename std::remove_const<T>::type, N> & data ) VULKAN_HPP_NOEXCEPT
: m_count( static_cast<uint32_t>( data.size() ) )
, m_ptr( data.data() )
{}
# endif
const T * begin() const VULKAN_HPP_NOEXCEPT const T * begin() const VULKAN_HPP_NOEXCEPT
{ {
return m_ptr; return m_ptr;
@ -549,6 +583,36 @@ namespace VULKAN_HPP_NAMESPACE
typename std::enable_if<std::is_const<B>::value, int>::type = 0> typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxyNoTemporaries( std::vector<typename std::remove_const<T>::type, Allocator> && data ) = delete; ArrayProxyNoTemporaries( std::vector<typename std::remove_const<T>::type, Allocator> && data ) = delete;
# if defined( VULKAN_HPP_SUPPORT_SPAN )
template <size_t N = std::dynamic_extent>
ArrayProxyNoTemporaries( std::span<T, N> const & data ) VULKAN_HPP_NOEXCEPT
: m_count( static_cast<uint32_t>( data.size() ) )
, m_ptr( data.data() )
{}
template <size_t N = std::dynamic_extent,
typename B = T,
typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxyNoTemporaries( std::span<typename std::remove_const<T>::type, N> const & data ) VULKAN_HPP_NOEXCEPT
: m_count( static_cast<uint32_t>( data.size() ) )
, m_ptr( data.data() )
{}
template <size_t N = std::dynamic_extent>
ArrayProxyNoTemporaries( std::span<T, N> & data ) VULKAN_HPP_NOEXCEPT
: m_count( static_cast<uint32_t>( data.size() ) )
, m_ptr( data.data() )
{}
template <size_t N = std::dynamic_extent,
typename B = T,
typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxyNoTemporaries( std::span<typename std::remove_const<T>::type, N> & data ) VULKAN_HPP_NOEXCEPT
: m_count( static_cast<uint32_t>( data.size() ) )
, m_ptr( data.data() )
{}
# endif
const T * begin() const VULKAN_HPP_NOEXCEPT const T * begin() const VULKAN_HPP_NOEXCEPT
{ {
return m_ptr; return m_ptr;