[WIP] test on ArrayProxy

This commit is contained in:
asuessenbach 2020-04-09 17:01:24 +02:00 committed by Markus Tavenrath
parent ccba30cc65
commit d40c96b45e
4 changed files with 295 additions and 42 deletions

View File

@ -5492,14 +5492,25 @@ int main(int argc, char **argv)
class ArrayProxy
{
public:
VULKAN_HPP_CONSTEXPR ArrayProxy() VULKAN_HPP_NOEXCEPT
: m_count(0)
, m_ptr(nullptr)
{}
VULKAN_HPP_CONSTEXPR ArrayProxy(std::nullptr_t) VULKAN_HPP_NOEXCEPT
: m_count(0)
, m_ptr(nullptr)
{}
ArrayProxy(typename std::remove_reference<T>::type & ptr) VULKAN_HPP_NOEXCEPT
ArrayProxy(T & value) VULKAN_HPP_NOEXCEPT
: m_count(1)
, m_ptr(&ptr)
, m_ptr(&value)
{}
template<typename B = T, typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxy(typename std::remove_const<T>::type & value) VULKAN_HPP_NOEXCEPT
: m_count(1)
, m_ptr(&value)
{}
ArrayProxy(uint32_t count, T * ptr) VULKAN_HPP_NOEXCEPT
@ -5507,33 +5518,44 @@ int main(int argc, char **argv)
, m_ptr(ptr)
{}
template <size_t N>
ArrayProxy(std::array<typename std::remove_const<T>::type, N> & data) VULKAN_HPP_NOEXCEPT
: m_count(N)
, m_ptr(data.data())
template<typename B = T, typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxy(uint32_t count, typename std::remove_const<T>::type * ptr) VULKAN_HPP_NOEXCEPT
: m_count(count)
, m_ptr(ptr)
{}
template <size_t N>
ArrayProxy(std::array<typename std::remove_const<T>::type, N> const& data) VULKAN_HPP_NOEXCEPT
: m_count(N)
, m_ptr(data.data())
ArrayProxy(std::initializer_list<T> const& list) VULKAN_HPP_NOEXCEPT
: m_count(static_cast<uint32_t>(list.size()))
, m_ptr(list.begin())
{}
template <class Allocator = std::allocator<typename std::remove_const<T>::type>>
ArrayProxy(std::vector<typename std::remove_const<T>::type, Allocator> & data) VULKAN_HPP_NOEXCEPT
: m_count(static_cast<uint32_t>(data.size()))
, m_ptr(data.data())
template<typename B = T, typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxy(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 <class Allocator = std::allocator<typename std::remove_const<T>::type>>
ArrayProxy(std::vector<typename std::remove_const<T>::type, Allocator> const& data) VULKAN_HPP_NOEXCEPT
: m_count(static_cast<uint32_t>(data.size()))
, m_ptr(data.data())
ArrayProxy(std::initializer_list<T> & list) VULKAN_HPP_NOEXCEPT
: m_count(static_cast<uint32_t>(list.size()))
, m_ptr(list.begin())
{}
ArrayProxy(std::initializer_list<typename std::remove_reference<T>::type> const& data) VULKAN_HPP_NOEXCEPT
: m_count(static_cast<uint32_t>(data.end() - data.begin()))
, m_ptr(data.begin())
template<typename B = T, typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxy(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 Container>
ArrayProxy(Container const& container) VULKAN_HPP_NOEXCEPT
: m_count(static_cast<uint32_t>(container.size()))
, m_ptr(container.data())
{}
template <typename Container>
ArrayProxy(Container & container) VULKAN_HPP_NOEXCEPT
: m_count(static_cast<uint32_t>(container.size()))
, m_ptr(container.data())
{}
const T * begin() const VULKAN_HPP_NOEXCEPT

View File

@ -0,0 +1,172 @@
// Copyright(c) 2018, NVIDIA CORPORATION. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// VulkanHpp Samples : ArrayProxy
// Compile test on using vk::ArrayProxy
#include "vulkan/vulkan.hpp"
#include <iostream>
static char const* AppName = "ArrayProxy";
static char const* EngineName = "Vulkan.hpp";
void fct(vk::ArrayProxy<int> /*ap*/)
{}
void fctc(vk::ArrayProxy<const int> /*ap*/)
{}
int main(int /*argc*/, char ** /*argv*/)
{
try
{
// nullptr_t
fct(nullptr);
fctc(nullptr);
vk::ArrayProxy<int> ap0 = nullptr;
assert(ap0.size() == 0);
// Type
//fct(2); // not supported: cannot convert from 'const int *' to 'T *'
fctc(1);
int i0 = 1;
fct(i0);
fctc(i0);
const int i1 = 2;
//fct(i1); // not supported: cannot convert from 'const int *' to 'T *'
fctc(i1);
// count, T *
int* i0p = &i0;
fct({ 1, i0p });
fctc({ 1, i0p });
// count, T const*
int const* i1p = &i1;
//fct({ 1, i1p }); // not supported: cannot convert from 'const int *' to 'T *'
fctc({ 1, i1p });
// std::array<T,N>
std::array<int, 2> sa0 = { 0, 1 };
fct(sa0);
fctc(sa0);
// std::array<T,N> const
std::array<const int, 2> sa1 = { 0, 1 };
//fct(sa1); // not supported: cannot convert from '_Ty *' to 'T *'
fctc(sa1);
std::array<int, 2> const sa2 = { 1, 2 };
//fct(sa2); // not supported: cannot convert from 'const _Ty *' to 'T *'
fctc(sa2);
std::array<const int, 2> const sa3 = { 1, 2 };
//fct(sa3); // not supported: cannot convert from '_Ty *' to 'T *'
fctc(sa3);
vk::ArrayProxy<int> ap2 = sa0;
assert(ap2.size() == 2);
//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> ap5 = sa3; // not supported: cannot convert from '_Ty *' to 'T *'
vk::ArrayProxy<const int> ap6 = sa0;
assert(ap6.size() == 2);
vk::ArrayProxy<const int> ap7 = sa1;
assert(ap7.size() == 2);
vk::ArrayProxy<const int> ap8 = sa2;
assert(ap8.size() == 2);
vk::ArrayProxy<const int> ap9 = sa3;
assert(ap9.size() == 2);
// std::vector<T>
std::vector<int> sv0 = { 0, 1 };
fct(sv0);
fctc(sv0);
std::vector<int> const sv1 = { 0, 1 };
//fct(sv1); // not supported: cannot convert from 'const _Ty *' to 'T *'
fctc(sv1);
vk::ArrayProxy<int> ap10 = sv0;
assert(ap10.size() == 2);
//vk::ArrayProxy<int> ap11 = sv1; // not supported: cannot convert from '_Ty *' to 'T *'
vk::ArrayProxy<const int> ap12 = sv0;
assert(ap12.size() == 2);
vk::ArrayProxy<const int> ap13 = sv1;
assert(ap13.size() == 2);
// std::initializer_list
fct({});
fctc({});
//fct({ 0, 1 }); // not supported: cannot convert from 'const _Elem *' to 'T *'
fctc({ 0, 1 });
int a = 0;
int b = 1;
//fct({ a, b }); // not supported: cannot convert from 'const _Elem *' to 'T *'
fctc({ a,b });
auto il0 = { 0, 1 }; // -> std::initializer_list<int>
//fct(il0); // not supported: cannot convert from 'const _Elem *' to 'T *'
fctc(il0);
std::initializer_list<int> il1 = { 0, 1 };
//fct(il1); // not supported: cannot convert from 'const _Elem *' to 'T *'
fctc(il1);
std::initializer_list<const int> il2 = { 0, 1 };
//fct(il2); // not supported: cannot convert from '_Elem *' to 'T *'
fctc(il2);
std::initializer_list<int> const il3 = { 0, 1 };
//fct(il3); // not supported: cannot convert from 'const _Elem *' to 'T *'
fctc(il3);
std::initializer_list<const int> const il4 = { 0, 1 };
//fct(il4); // not supported: cannot convert from 'const _Elem *' to 'T *'
fctc(il4);
//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> 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<const int> ap18 = il1;
assert(ap18.size() == 2);
vk::ArrayProxy<const int> ap19 = il2;
assert(ap19.size() == 2);
vk::ArrayProxy<const int> ap20 = il3;
assert(ap20.size() == 2);
vk::ArrayProxy<const int> ap21 = il4;
assert(ap21.size() == 2);
}
catch (vk::SystemError const& err)
{
std::cout << "vk::SystemError: " << err.what() << std::endl;
exit(-1);
}
catch (...)
{
std::cout << "unknown error\n";
exit(-1);
}
return 0;
}

View File

@ -0,0 +1,37 @@
# Copyright(c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.2)
if (NOT TESTS_BUILD_ONLY_DYNAMIC)
project(ArrayProxy)
set(HEADERS
)
set(SOURCES
ArrayProxy.cpp
)
source_group(headers FILES ${HEADERS})
source_group(sources FILES ${SOURCES})
add_executable(ArrayProxy
${HEADERS}
${SOURCES}
)
set_target_properties(ArrayProxy PROPERTIES FOLDER "Tests")
target_link_libraries(ArrayProxy "${Vulkan_LIBRARIES}")
endif()

View File

@ -185,14 +185,25 @@ namespace VULKAN_HPP_NAMESPACE
class ArrayProxy
{
public:
VULKAN_HPP_CONSTEXPR ArrayProxy() VULKAN_HPP_NOEXCEPT
: m_count(0)
, m_ptr(nullptr)
{}
VULKAN_HPP_CONSTEXPR ArrayProxy(std::nullptr_t) VULKAN_HPP_NOEXCEPT
: m_count(0)
, m_ptr(nullptr)
{}
ArrayProxy(typename std::remove_reference<T>::type & ptr) VULKAN_HPP_NOEXCEPT
ArrayProxy(T & value) VULKAN_HPP_NOEXCEPT
: m_count(1)
, m_ptr(&ptr)
, m_ptr(&value)
{}
template<typename B = T, typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxy(typename std::remove_const<T>::type & value) VULKAN_HPP_NOEXCEPT
: m_count(1)
, m_ptr(&value)
{}
ArrayProxy(uint32_t count, T * ptr) VULKAN_HPP_NOEXCEPT
@ -200,33 +211,44 @@ namespace VULKAN_HPP_NAMESPACE
, m_ptr(ptr)
{}
template <size_t N>
ArrayProxy(std::array<typename std::remove_const<T>::type, N> & data) VULKAN_HPP_NOEXCEPT
: m_count(N)
, m_ptr(data.data())
template<typename B = T, typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxy(uint32_t count, typename std::remove_const<T>::type * ptr) VULKAN_HPP_NOEXCEPT
: m_count(count)
, m_ptr(ptr)
{}
template <size_t N>
ArrayProxy(std::array<typename std::remove_const<T>::type, N> const& data) VULKAN_HPP_NOEXCEPT
: m_count(N)
, m_ptr(data.data())
ArrayProxy(std::initializer_list<T> const& list) VULKAN_HPP_NOEXCEPT
: m_count(static_cast<uint32_t>(list.size()))
, m_ptr(list.begin())
{}
template <class Allocator = std::allocator<typename std::remove_const<T>::type>>
ArrayProxy(std::vector<typename std::remove_const<T>::type, Allocator> & data) VULKAN_HPP_NOEXCEPT
: m_count(static_cast<uint32_t>(data.size()))
, m_ptr(data.data())
template<typename B = T, typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxy(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 <class Allocator = std::allocator<typename std::remove_const<T>::type>>
ArrayProxy(std::vector<typename std::remove_const<T>::type, Allocator> const& data) VULKAN_HPP_NOEXCEPT
: m_count(static_cast<uint32_t>(data.size()))
, m_ptr(data.data())
ArrayProxy(std::initializer_list<T> & list) VULKAN_HPP_NOEXCEPT
: m_count(static_cast<uint32_t>(list.size()))
, m_ptr(list.begin())
{}
ArrayProxy(std::initializer_list<typename std::remove_reference<T>::type> const& data) VULKAN_HPP_NOEXCEPT
: m_count(static_cast<uint32_t>(data.end() - data.begin()))
, m_ptr(data.begin())
template<typename B = T, typename std::enable_if<std::is_const<B>::value, int>::type = 0>
ArrayProxy(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 Container>
ArrayProxy(Container const& container) VULKAN_HPP_NOEXCEPT
: m_count(static_cast<uint32_t>(container.size()))
, m_ptr(container.data())
{}
template <typename Container>
ArrayProxy(Container & container) VULKAN_HPP_NOEXCEPT
: m_count(static_cast<uint32_t>(container.size()))
, m_ptr(container.data())
{}
const T * begin() const VULKAN_HPP_NOEXCEPT