// 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 : ArrayProxyNoTemporaries // Compile test on using vk::ArrayProxyNoTemporaries #if defined( _MSC_VER ) // no need to ignore any warnings with MSVC #elif defined( __clang__ ) # pragma clang diagnostic ignored "-Wunused-variable" #elif defined( __GNUC__ ) # pragma GCC diagnostic ignored "-Wunused-but-set-variable" #else // unknown compiler... just ignore the warnings for yourselves ;) #endif #include #include void fct( vk::ArrayProxyNoTemporaries /*ap*/ ) {} void fctc( vk::ArrayProxyNoTemporaries /*ap*/ ) {} int getInt() { return 1; } int ( &&getArrayReference() )[2] { static int arr[2] = { 1, 2 }; return std::move( arr ); } int const ( &&getConstArrayReference() )[2] { static int const arr[2] = { 1, 2 }; return std::move( arr ); } std::array getArray() { return { 1, 2 }; } std::array const getConstArray() { return { 1, 2 }; } std::vector getVector() { return { 1, 2 }; } std::vector const getConstVector() { return { 1, 2 }; } std::initializer_list getInitializerList() { return { 1, 2 }; } std::initializer_list const getConstInitializerList() { return { 1, 2 }; } int main( int /*argc*/, char ** /*argv*/ ) { try { // no args fct( {} ); fctc( {} ); // nullptr_t fct( nullptr ); fctc( nullptr ); vk::ArrayProxyNoTemporaries apnt1 = nullptr; assert( apnt1.size() == 0 ); // Type // fct(2); // not supported: cannot convert argument 1 from 'int' to 'vk::ArrayProxyNoTemporaries' // fctc(1); // not supported: cannot convert argument 1 from 'int' to 'vk::ArrayProxyNoTemporaries' // getInt() // fct( getInt() ); // not supported: cannot convert argument 1 from 'int' to 'vk::ArrayProxyNoTemporaries' // fctc( getInt() ); // not supported: cannot convert argument 1 from 'int' to 'vk::ArrayProxyNoTemporaries' int i0 = 1; fct( i0 ); fctc( i0 ); const int i1 = 2; // fct(i1); // not supported: cannot convert from 'const int *' to 'T * fctc( i1 ); // vk::ArrayProxyNoTemporaries apnt2 = 1; // not supported: cannot convert from 'int' to 'vk::ArrayProxyNoTemporaries' // vk::ArrayProxyNoTemporaries apnt3 = 1; // not supported: cannot convert from 'int' to 'vk::ArrayProxyNoTemporaries' vk::ArrayProxyNoTemporaries apnt4 = i0; assert( apnt4.size() == 1 ); vk::ArrayProxyNoTemporaries apnt5 = i1; assert( apnt5.size() == 1 ); // 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::ArrayProxyNoTemporaries' fctc( { 1, i1p } ); vk::ArrayProxyNoTemporaries apnt6 = { 1, i0p }; assert( apnt6.size() == 1 ); vk::ArrayProxyNoTemporaries apnt7 = { 1, i1p }; assert( apnt7.size() == 1 ); // T[count] int ia0[2] = { 0, 1 }; fct( ia0 ); fctc( ia0 ); // const T[count] const int ia1[2] = { 0, 1 }; // fct( ia1 ); // not supported: cannot convert argument 1 from 'const int [2]' to 'vk::ArrayProxyNoTemporaries' fctc( ia1 ); vk::ArrayProxyNoTemporaries apnt8 = ia0; assert( apnt8.size() == 2 ); vk::ArrayProxyNoTemporaries apnt9 = ia1; assert( apnt9.size() == 2 ); // getArrayReference // fct( getConstArrayReference() ); // not supported: cannot convert argument 1 from 'const int [2]' to 'vk::ArrayProxyNoTemporaries' // fctc( getConstArrayReference() ); // not supported: attempting to reference a deleted function // fct( getArrayReference() ); // not supported: attempting to reference a deleted function // fctc( getArrayReference() ); // not supported: attempting to reference a deleted function // std::array std::array sa0 = { 0, 1 }; fct( sa0 ); fctc( sa0 ); // std::array std::array sa1 = { 0, 1 }; // fct( sa1 ); // not supported: cannot convert argument 1 from 'std::array' to 'vk::ArrayProxyNoTemporaries' fctc( sa1 ); // std::array const std::array const sa2 = { 1, 2 }; // fct( sa2 ); // not supported: cannot convert argument 1 from 'const std::array' to 'vk::ArrayProxyNoTemporaries' fctc( sa2 ); // std::array const std::array const sa3 = { 1, 2 }; // fct( sa3 ); // not supported: cannot convert argument 1 from 'const std::array' to 'vk::ArrayProxyNoTemporaries' fctc( sa3 ); // getArray // fct( getConstArray() ); // not supported: cannot convert argument 1 from 'const std::array' to 'vk::ArrayProxyNoTemporaries' // fctc( getConstArray() ); // not supported: cannot convert argument 1 from 'const std::array' to 'vk::ArrayProxyNoTemporaries' // fct( getArray() ); // not supported: cannot convert argument 1 from 'std::array' to 'vk::ArrayProxyNoTemporaries' // fctc( getArray() ); // not supported: cannot convert argument 1 from 'std::array' to 'vk::ArrayProxyNoTemporaries' // from std::array constructors vk::ArrayProxyNoTemporaries apnt10 = sa0; assert( apnt10.size() == 2 ); // vk::ArrayProxyNoTemporaries apnt11 = sa1; // not supported: cannot convert from 'std::array' to 'vk::ArrayProxyNoTemporaries' // vk::ArrayProxyNoTemporaries apnt12 = sa2; // not supported: cannot convert from 'const std::array' to 'vk::ArrayProxyNoTemporaries' // vk::ArrayProxyNoTemporaries apnt13 = sa3; // not supported: cannot convert from 'const std::array' to // 'vk::ArrayProxyNoTemporaries' vk::ArrayProxyNoTemporaries apnt14 = sa0; assert( apnt14.size() == 2 ); vk::ArrayProxyNoTemporaries apnt15 = sa1; assert( apnt15.size() == 2 ); vk::ArrayProxyNoTemporaries apnt16 = sa2; assert( apnt16.size() == 2 ); vk::ArrayProxyNoTemporaries apnt17 = sa3; assert( apnt17.size() == 2 ); // std::vector std::vector sv0 = { 0, 1 }; fct( sv0 ); fctc( sv0 ); // std::vector const std::vector const sv1 = { 0, 1 }; // fct( sv1 ); // not supported: cannot convert argument 1 from 'const std::vector>' to 'vk::ArrayProxyNoTemporaries' fctc( sv1 ); // getVector // fct( getConstVector() ); // not supported: cannot convert argument 1 from 'const std::vector>' to 'vk::ArrayProxyNoTemporaries' // fctc( getConstVector() ); // not supported: cannot convert argument 1 from 'const std::vector>' to 'vk::ArrayProxyNoTemporaries' // fct( getVector() ); // not supported: cannot convert argument 1 from 'std::vector>' to 'vk::ArrayProxyNoTemporaries' // fctc( getVector() ); // not supported: cannot convert argument 1 from 'std::vector>' to 'vk::ArrayProxyNoTemporaries' vk::ArrayProxyNoTemporaries apnt18 = sv0; assert( apnt18.size() == 2 ); // vk::ArrayProxyNoTemporaries apnt19 = sv1; // not supported: cannot convert from 'const std::vector>' to 'vk::ArrayProxyNoTemporaries' vk::ArrayProxyNoTemporaries apnt20 = sv0; assert( apnt20.size() == 2 ); vk::ArrayProxyNoTemporaries apnt21 = sv1; assert( apnt21.size() == 2 ); // std::initializer_list // fct( { 0, 1 } ); // not supported: cannot convert argument 1 from 'initializer list' to 'vk::ArrayProxyNoTemporaries' // fctc( { 0, 1 } ); // not supported: cannot convert argument 1 from 'initializer list' to 'vk::ArrayProxyNoTemporaries' // int a = 0; // int b = 1; // fct( { a, b } ); // not supported: cannot convert argument 1 from 'initializer list' to 'vk::ArrayProxyNoTemporaries' // fctc( { a, b } ); // not supported: cannot convert argument 1 from 'initializer list' to 'vk::ArrayProxyNoTemporaries' auto il0 = { 0, 1 }; // -> std::initializer_list // fct( il0 ); // not supported: cannot convert from 'const int *' to 'int *' fctc( il0 ); std::initializer_list il1 = { 0, 1 }; // fct( il1 ); // not supported: cannot convert argument 1 from 'std::initializer_list<_Ty>' to 'vk::ArrayProxyNoTemporaries' fctc( il1 ); std::initializer_list il2 = { 0, 1 }; // fct( il2 ); // not supported: cannot convert argument 1 from 'std::initializer_list' to 'vk::ArrayProxyNoTemporaries' fctc( il2 ); std::initializer_list const il3 = { 0, 1 }; // fct( il3 ); // not supported: cannot convert argument 1 from 'const std::initializer_list<_Ty>' to 'vk::ArrayProxyNoTemporaries' fctc( il3 ); std::initializer_list const il4 = { 0, 1 }; // fct( il4 ); // not supported: cannot convert argument 1 from 'const std::initializer_list' to 'vk::ArrayProxyNoTemporaries' fctc( il4 ); // getInitializerList // fct( getConstInitializerList() ); // not supported: cannot convert argument 1 from 'const std::initializer_list<_Ty>' to 'vk::ArrayProxyNoTemporaries' // fctc( getConstInitializerList() ); // not supported: cannot convert argument 1 from 'const std::initializer_list<_Ty>' to 'vk::ArrayProxyNoTemporaries' // fct( getInitializerList() ); // not supported: cannot convert argument 1 from 'std::initializer_list<_Ty>' to 'vk::ArrayProxyNoTemporaries' // fctc( getInitializerList() ); // not supported: cannot convert argument 1 from 'std::initializer_list<_Ty>' to 'vk::ArrayProxyNoTemporaries' // vk::ArrayProxyNoTemporaries apnt22 = il1; // not supported: cannot convert from 'std::initializer_list<_Ty>' to 'vk::ArrayProxyNoTemporaries' // vk::ArrayProxyNoTemporaries apnt23 = il2; // not supported: cannot convert from 'std::initializer_list' to 'vk::ArrayProxyNoTemporaries' // vk::ArrayProxyNoTemporaries apnt24 = il3; // not supported: cannot convert from 'const std::initializer_list<_Ty>' to 'vk::ArrayProxyNoTemporaries' // vk::ArrayProxyNoTemporaries apnt25 = il4; // not supported: cannot convert from 'const std::initializer_list' to 'vk::ArrayProxyNoTemporaries' vk::ArrayProxyNoTemporaries apnt26 = {}; assert( apnt26.size() == 0 ); // vk::ArrayProxyNoTemporaries apnt27 = { 0, 1 }; // not supported: cannot convert from 'initializer list' to 'vk::ArrayProxyNoTemporaries' vk::ArrayProxyNoTemporaries apnt28 = il1; assert( apnt28.size() == 2 ); vk::ArrayProxyNoTemporaries apnt29 = il2; assert( apnt29.size() == 2 ); vk::ArrayProxyNoTemporaries apnt30 = il3; assert( apnt30.size() == 2 ); vk::ArrayProxyNoTemporaries apnt31 = il4; assert( apnt31.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; }