// 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 #if ( 20 <= VULKAN_HPP_CPP_VERSION ) # include #endif void fct( vk::ArrayProxy /*ap*/ ) {} void fctc( vk::ArrayProxy /*ap*/ ) {} int main( int /*argc*/, char ** /*argv*/ ) { try { // to prevent a warning on unreferenced function vk::getDispatchLoaderStatic, use just one arbitrary vk-function (void)vk::enumerateInstanceVersion(); // nullptr_t fct( nullptr ); fctc( nullptr ); vk::ArrayProxy ap0 = nullptr; assert( ap0.size() == 0 ); // Type // fct(2); // not supported: cannot convert argument 1 from 'int' to 'vk::ArrayProxy' fctc( 1 ); int i0 = 1; fct( i0 ); fctc( i0 ); const int i1 = 2; // fct(i1); // not supported: cannot convert argument 1 from 'const int' to 'vk::ArrayProxy' 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 argument 1 from 'initializer list' to 'vk::ArrayProxy' fctc( { 1, i1p } ); // std::array std::array sa0 = { 0, 1 }; fct( sa0 ); fctc( sa0 ); // std::array const std::array sa1 = { 0, 1 }; // fct(sa1); // not supported: cannot convert argument 1 from 'std::array' to 'vk::ArrayProxy' fctc( sa1 ); std::array const sa2 = { 1, 2 }; // fct(sa2); // not supported: cannot convert from 'const _Ty *' to 'T *' fctc( sa2 ); std::array const sa3 = { 1, 2 }; // fct(sa3); // not supported: cannot convert argument 1 from 'const std::array' to 'vk::ArrayProxy' fctc( sa3 ); vk::ArrayProxy ap2 = sa0; assert( ap2.size() == 2 ); // vk::ArrayProxy ap3 = sa1; // not supported: cannot convert from 'std::array' to 'vk::ArrayProxy' // vk::ArrayProxy ap4 = sa2; // not supported: cannot convert from '_Ty *' to 'T *' // vk::ArrayProxy ap5 = sa3; // not supported: cannot convert from 'const std::array' to 'vk::ArrayProxy' vk::ArrayProxy ap6 = sa0; assert( ap6.size() == 2 ); vk::ArrayProxy ap7 = sa1; assert( ap7.size() == 2 ); vk::ArrayProxy ap8 = sa2; assert( ap8.size() == 2 ); vk::ArrayProxy ap9 = sa3; assert( ap9.size() == 2 ); // std::vector std::vector sv0 = { 0, 1 }; fct( sv0 ); fctc( sv0 ); std::vector const sv1 = { 0, 1 }; // fct(sv1); // not supported: cannot convert from 'const _Ty *' to 'T *' fctc( sv1 ); vk::ArrayProxy ap10 = sv0; assert( ap10.size() == 2 ); // vk::ArrayProxy ap11 = sv1; // not supported: cannot convert from '_Ty *' to 'T *' vk::ArrayProxy ap12 = sv0; assert( ap12.size() == 2 ); vk::ArrayProxy 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 // fct(il0); // not supported: cannot convert from 'const _Elem *' to 'T *' fctc( il0 ); std::initializer_list il1 = { 0, 1 }; // fct(il1); // not supported: cannot convert from 'const _Elem *' to 'T *' fctc( il1 ); std::initializer_list il2 = { 0, 1 }; // fct(il2); // not supported: cannot convert argument 1 from 'std::initializer_list' to 'vk::ArrayProxy' fctc( il2 ); std::initializer_list const il3 = { 0, 1 }; // fct(il3); // not supported: cannot convert from 'const _Elem *' to 'T *' fctc( il3 ); std::initializer_list const il4 = { 0, 1 }; // fct(il4); // not supported: cannot convert argument 1 from 'const std::initializer_list' to 'vk::ArrayProxy' fctc( il4 ); // vk::ArrayProxy ap14 = il1; // not supported: cannot convert from 'const _Elem *' to 'T *' // vk::ArrayProxy ap15 = il2; // not supported: cannot convert from 'std::initializer_list' to 'vk::ArrayProxy' // vk::ArrayProxy ap16 = il3; // not supported: cannot convert from 'const _Elem *' to 'T *' // vk::ArrayProxy ap17 = il4; // not supported: cannot convert from 'const std::initializer_list' to 'vk::ArrayProxy' vk::ArrayProxy ap18 = il1; assert( ap18.size() == 2 ); vk::ArrayProxy ap19 = il2; assert( ap19.size() == 2 ); vk::ArrayProxy ap20 = il3; assert( ap20.size() == 2 ); vk::ArrayProxy ap21 = il4; assert( ap21.size() == 2 ); #if defined( VULKAN_HPP_SUPPORT_SPAN ) // std::span std::span ss0( sa0.begin(), sa0.size() ); fct( ss0 ); fctc( ss0 ); // std::span const std::span ss1( sa1.begin(), sa1.size() ); // fct(ss1); // not supported: cannot convert from 'std::span' to 'vk::ArrayProxy' fctc( ss1 ); std::span const ss2; fct( ss2 ); fctc( ss2 ); std::span const ss3( sa3.begin(), sa3.end() ); // fct(ss3); // not supported: cannot convert from 'const std::span' to 'vk::ArrayProxy' fctc( ss3 ); #endif } 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; }