2021-01-14 10:41:30 +00:00
// 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
2022-03-02 15:26:09 +00:00
# if defined( _MSC_VER )
// no need to ignore any warnings with MSVC
2023-10-24 16:27:35 +00:00
# elif defined( __clang__ )
# pragma clang diagnostic ignored "-Wunused-variable"
2022-03-02 15:26:09 +00:00
# elif defined( __GNUC__ )
2023-10-24 16:27:35 +00:00
# pragma GCC diagnostic ignored "-Wunused-but-set-variable"
2022-03-02 15:26:09 +00:00
# else
2023-10-24 16:27:35 +00:00
// unknown compiler... just ignore the warnings for yourselves ;)
2022-03-02 15:26:09 +00:00
# endif
2021-01-14 10:41:30 +00:00
# include <iostream>
2022-08-10 09:19:06 +00:00
# include <vulkan/vulkan.hpp>
2021-01-14 10:41:30 +00:00
2022-02-28 09:11:04 +00:00
void fct ( vk : : ArrayProxyNoTemporaries < int > /*ap*/ ) { }
2021-01-14 10:41:30 +00:00
2022-02-28 09:11:04 +00:00
void fctc ( vk : : ArrayProxyNoTemporaries < const int > /*ap*/ ) { }
2021-01-14 10:41:30 +00:00
int getInt ( )
{
return 1 ;
}
2024-06-25 15:43:55 +00:00
int ( & & getArrayReference ( ) ) [ 2 ]
2022-04-15 15:38:23 +00:00
{
static int arr [ 2 ] = { 1 , 2 } ;
return std : : move ( arr ) ;
}
2024-06-25 15:43:55 +00:00
int const ( & & getConstArrayReference ( ) ) [ 2 ]
2022-04-15 15:38:23 +00:00
{
static int const arr [ 2 ] = { 1 , 2 } ;
return std : : move ( arr ) ;
}
2021-01-14 10:41:30 +00:00
std : : array < int , 2 > getArray ( )
{
return { 1 , 2 } ;
}
std : : array < int , 2 > const getConstArray ( )
{
return { 1 , 2 } ;
}
std : : vector < int > getVector ( )
{
return { 1 , 2 } ;
}
std : : vector < int > const getConstVector ( )
{
return { 1 , 2 } ;
}
2024-06-25 15:43:55 +00:00
std : : initializer_list < int > getInitializerList ( )
{
return { 1 , 2 } ;
}
2023-10-18 11:45:14 +00:00
2024-06-25 15:43:55 +00:00
std : : initializer_list < int > const getConstInitializerList ( )
{
return { 1 , 2 } ;
}
2021-01-14 10:41:30 +00:00
int main ( int /*argc*/ , char * * /*argv*/ )
{
try
{
2024-06-25 15:43:55 +00:00
// no args
fct ( { } ) ;
fctc ( { } ) ;
2021-01-14 10:41:30 +00:00
// nullptr_t
2022-02-28 09:11:04 +00:00
fct ( nullptr ) ;
fctc ( nullptr ) ;
2021-01-14 10:41:30 +00:00
2024-06-25 15:43:55 +00:00
vk : : ArrayProxyNoTemporaries < int > apnt1 = nullptr ;
assert ( apnt1 . size ( ) = = 0 ) ;
2021-01-14 10:41:30 +00:00
// Type
2024-06-25 15:43:55 +00:00
// fct(2); // not supported: cannot convert argument 1 from 'int' to 'vk::ArrayProxyNoTemporaries<int>'
// fctc(1); // not supported: cannot convert argument 1 from 'int' to 'vk::ArrayProxyNoTemporaries<const int32_t>'
2021-01-14 10:41:30 +00:00
// getInt()
2024-06-25 15:43:55 +00:00
// fct( getInt() ); // not supported: cannot convert argument 1 from 'int' to 'vk::ArrayProxyNoTemporaries<int>'
// fctc( getInt() ); // not supported: cannot convert argument 1 from 'int' to 'vk::ArrayProxyNoTemporaries<const int32_t>'
2021-01-14 10:41:30 +00:00
int i0 = 1 ;
2022-02-28 09:11:04 +00:00
fct ( i0 ) ;
fctc ( i0 ) ;
2021-01-14 10:41:30 +00:00
const int i1 = 2 ;
2024-06-25 15:43:55 +00:00
// fct(i1); // not supported: cannot convert from 'const int *' to 'T *
2022-02-28 09:11:04 +00:00
fctc ( i1 ) ;
2021-01-14 10:41:30 +00:00
2024-06-25 15:43:55 +00:00
// vk::ArrayProxyNoTemporaries<int> apnt2 = 1; // not supported: cannot convert from 'int' to 'vk::ArrayProxyNoTemporaries<int>'
// vk::ArrayProxyNoTemporaries<const int> apnt3 = 1; // not supported: cannot convert from 'int' to 'vk::ArrayProxyNoTemporaries<const int32_t>'
2022-04-15 15:38:23 +00:00
2024-06-25 15:43:55 +00:00
vk : : ArrayProxyNoTemporaries < const int > apnt4 = i0 ;
assert ( apnt4 . size ( ) = = 1 ) ;
vk : : ArrayProxyNoTemporaries < const int > apnt5 = i1 ;
assert ( apnt5 . size ( ) = = 1 ) ;
2022-04-15 15:38:23 +00:00
2021-01-14 10:41:30 +00:00
// count, T *
2022-02-28 09:11:04 +00:00
int * i0p = & i0 ;
fct ( { 1 , i0p } ) ;
fctc ( { 1 , i0p } ) ;
2021-01-14 10:41:30 +00:00
// count, T const*
2022-02-28 09:11:04 +00:00
int const * i1p = & i1 ;
2024-06-25 15:43:55 +00:00
// fct( { 1, i1p } ); // not supported: cannot convert argument 1 from 'initializer list' to 'vk::ArrayProxyNoTemporaries<int>'
2022-02-28 09:11:04 +00:00
fctc ( { 1 , i1p } ) ;
2021-01-14 10:41:30 +00:00
2024-06-25 15:43:55 +00:00
vk : : ArrayProxyNoTemporaries < const int > apnt6 = { 1 , i0p } ;
assert ( apnt6 . size ( ) = = 1 ) ;
vk : : ArrayProxyNoTemporaries < const int > apnt7 = { 1 , i1p } ;
assert ( apnt7 . size ( ) = = 1 ) ;
2022-04-15 15:38:23 +00:00
// 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<int>'
fctc ( ia1 ) ;
2024-06-25 15:43:55 +00:00
vk : : ArrayProxyNoTemporaries < const int > apnt8 = ia0 ;
assert ( apnt8 . size ( ) = = 2 ) ;
vk : : ArrayProxyNoTemporaries < const int > apnt9 = ia1 ;
assert ( apnt9 . size ( ) = = 2 ) ;
2022-04-15 15:38:23 +00:00
// getArrayReference
2024-06-25 15:43:55 +00:00
// fct( getConstArrayReference() ); // not supported: cannot convert argument 1 from 'const int [2]' to 'vk::ArrayProxyNoTemporaries<int>'
// 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
2022-04-15 15:38:23 +00:00
2021-01-14 10:41:30 +00:00
// std::array<T,N>
std : : array < int , 2 > sa0 = { 0 , 1 } ;
2022-02-28 09:11:04 +00:00
fct ( sa0 ) ;
fctc ( sa0 ) ;
2021-01-14 10:41:30 +00:00
// std::array<const T,N>
std : : array < const int , 2 > sa1 = { 0 , 1 } ;
2024-06-25 15:43:55 +00:00
// fct( sa1 ); // not supported: cannot convert argument 1 from 'std::array<const int,2>' to 'vk::ArrayProxyNoTemporaries<int>'
2022-02-28 09:11:04 +00:00
fctc ( sa1 ) ;
2021-01-14 10:41:30 +00:00
// std::array<T,N> const
std : : array < int , 2 > const sa2 = { 1 , 2 } ;
2024-06-25 15:43:55 +00:00
// fct( sa2 ); // not supported: cannot convert argument 1 from 'const std::array<int,2>' to 'vk::ArrayProxyNoTemporaries<int>'
2022-02-28 09:11:04 +00:00
fctc ( sa2 ) ;
2021-01-14 10:41:30 +00:00
// std::array<const T,N> const
std : : array < const int , 2 > const sa3 = { 1 , 2 } ;
2024-06-25 15:43:55 +00:00
// fct( sa3 ); // not supported: cannot convert argument 1 from 'const std::array<const int,2>' to 'vk::ArrayProxyNoTemporaries<int>'
2022-02-28 09:11:04 +00:00
fctc ( sa3 ) ;
2021-01-14 10:41:30 +00:00
// getArray
2024-06-25 15:43:55 +00:00
// fct( getConstArray() ); // not supported: cannot convert argument 1 from 'const std::array<int,2>' to 'vk::ArrayProxyNoTemporaries<int>'
// fctc( getConstArray() ); // not supported: cannot convert argument 1 from 'const std::array<int,2>' to 'vk::ArrayProxyNoTemporaries<const int32_t>'
// fct( getArray() ); // not supported: cannot convert argument 1 from 'std::array<int,2>' to 'vk::ArrayProxyNoTemporaries<int>'
// fctc( getArray() ); // not supported: cannot convert argument 1 from 'std::array<int,2>' to 'vk::ArrayProxyNoTemporaries<const int32_t>'
2021-01-14 10:41:30 +00:00
// from std::array constructors
2024-06-25 15:43:55 +00:00
vk : : ArrayProxyNoTemporaries < int > apnt10 = sa0 ;
assert ( apnt10 . size ( ) = = 2 ) ;
// vk::ArrayProxyNoTemporaries<int> apnt11 = sa1; // not supported: cannot convert from 'std::array<const int,2>' to 'vk::ArrayProxyNoTemporaries<int>'
// vk::ArrayProxyNoTemporaries<int> apnt12 = sa2; // not supported: cannot convert from 'const std::array<int,2>' to 'vk::ArrayProxyNoTemporaries<int>'
// vk::ArrayProxyNoTemporaries<int> apnt13 = sa3; // not supported: cannot convert from 'const std::array<const int,2>' to
// 'vk::ArrayProxyNoTemporaries<int>'
vk : : ArrayProxyNoTemporaries < const int > apnt14 = sa0 ;
assert ( apnt14 . size ( ) = = 2 ) ;
vk : : ArrayProxyNoTemporaries < const int > apnt15 = sa1 ;
assert ( apnt15 . size ( ) = = 2 ) ;
vk : : ArrayProxyNoTemporaries < const int > apnt16 = sa2 ;
assert ( apnt16 . size ( ) = = 2 ) ;
vk : : ArrayProxyNoTemporaries < const int > apnt17 = sa3 ;
assert ( apnt17 . size ( ) = = 2 ) ;
2021-01-14 10:41:30 +00:00
// std::vector<T>
std : : vector < int > sv0 = { 0 , 1 } ;
2022-02-28 09:11:04 +00:00
fct ( sv0 ) ;
fctc ( sv0 ) ;
2021-01-14 10:41:30 +00:00
// std::vector<T> const
std : : vector < int > const sv1 = { 0 , 1 } ;
2024-06-25 15:43:55 +00:00
// fct( sv1 ); // not supported: cannot convert argument 1 from 'const std::vector<int,std::allocator<int>>' to 'vk::ArrayProxyNoTemporaries<int>'
2022-02-28 09:11:04 +00:00
fctc ( sv1 ) ;
2021-01-14 10:41:30 +00:00
// getVector
2024-06-25 15:43:55 +00:00
// fct( getConstVector() ); // not supported: cannot convert argument 1 from 'const std::vector<int,std::allocator<int>>' to 'vk::ArrayProxyNoTemporaries<int>'
// fctc( getConstVector() ); // not supported: cannot convert argument 1 from 'const std::vector<int,std::allocator<int>>' to 'vk::ArrayProxyNoTemporaries<const int32_t>'
// fct( getVector() ); // not supported: cannot convert argument 1 from 'std::vector<int,std::allocator<int>>' to 'vk::ArrayProxyNoTemporaries<int>'
// fctc( getVector() ); // not supported: cannot convert argument 1 from 'std::vector<int,std::allocator<int>>' to 'vk::ArrayProxyNoTemporaries<const int32_t>'
2021-01-14 10:41:30 +00:00
2024-06-25 15:43:55 +00:00
vk : : ArrayProxyNoTemporaries < int > apnt18 = sv0 ;
assert ( apnt18 . size ( ) = = 2 ) ;
2022-04-15 15:38:23 +00:00
2024-06-25 15:43:55 +00:00
// vk::ArrayProxyNoTemporaries<int> apnt19 = sv1; // not supported: cannot convert from 'const std::vector<int,std::allocator<int>>' to 'vk::ArrayProxyNoTemporaries<int>'
2022-04-15 15:38:23 +00:00
2024-06-25 15:43:55 +00:00
vk : : ArrayProxyNoTemporaries < const int > apnt20 = sv0 ;
assert ( apnt20 . size ( ) = = 2 ) ;
vk : : ArrayProxyNoTemporaries < const int > apnt21 = sv1 ;
assert ( apnt21 . size ( ) = = 2 ) ;
2021-01-14 10:41:30 +00:00
// std::initializer_list
2024-06-25 15:43:55 +00:00
// fct( { 0, 1 } ); // not supported: cannot convert argument 1 from 'initializer list' to 'vk::ArrayProxyNoTemporaries<int>'
// fctc( { 0, 1 } ); // not supported: cannot convert argument 1 from 'initializer list' to 'vk::ArrayProxyNoTemporaries<const int32_t>'
2021-01-14 10:41:30 +00:00
2021-11-22 14:11:03 +00:00
// int a = 0;
// int b = 1;
2024-06-25 15:43:55 +00:00
// fct( { a, b } ); // not supported: cannot convert argument 1 from 'initializer list' to 'vk::ArrayProxyNoTemporaries<int>'
// fctc( { a, b } ); // not supported: cannot convert argument 1 from 'initializer list' to 'vk::ArrayProxyNoTemporaries<const int32_t>'
2021-01-14 10:41:30 +00:00
2022-02-28 09:11:04 +00:00
auto il0 = { 0 , 1 } ; // -> std::initializer_list<int>
2024-06-25 15:43:55 +00:00
// fct( il0 ); // not supported: cannot convert from 'const int *' to 'int *'
2022-02-28 09:11:04 +00:00
fctc ( il0 ) ;
2021-01-14 10:41:30 +00:00
std : : initializer_list < int > il1 = { 0 , 1 } ;
2024-06-25 15:43:55 +00:00
// fct( il1 ); // not supported: cannot convert argument 1 from 'std::initializer_list<_Ty>' to 'vk::ArrayProxyNoTemporaries<int>'
2022-02-28 09:11:04 +00:00
fctc ( il1 ) ;
2021-01-14 10:41:30 +00:00
std : : initializer_list < const int > il2 = { 0 , 1 } ;
2024-06-25 15:43:55 +00:00
// fct( il2 ); // not supported: cannot convert argument 1 from 'std::initializer_list<const int>' to 'vk::ArrayProxyNoTemporaries<int>'
2022-02-28 09:11:04 +00:00
fctc ( il2 ) ;
2021-01-14 10:41:30 +00:00
std : : initializer_list < int > const il3 = { 0 , 1 } ;
2024-06-25 15:43:55 +00:00
// fct( il3 ); // not supported: cannot convert argument 1 from 'const std::initializer_list<_Ty>' to 'vk::ArrayProxyNoTemporaries<int>'
2022-02-28 09:11:04 +00:00
fctc ( il3 ) ;
2021-01-14 10:41:30 +00:00
std : : initializer_list < const int > const il4 = { 0 , 1 } ;
2024-06-25 15:43:55 +00:00
// fct( il4 ); // not supported: cannot convert argument 1 from 'const std::initializer_list<const int>' to 'vk::ArrayProxyNoTemporaries<int>'
2022-02-28 09:11:04 +00:00
fctc ( il4 ) ;
2021-01-14 10:41:30 +00:00
// getInitializerList
2024-06-25 15:43:55 +00:00
// fct( getConstInitializerList() ); // not supported: cannot convert argument 1 from 'const std::initializer_list<_Ty>' to 'vk::ArrayProxyNoTemporaries<int>'
// fctc( getConstInitializerList() ); // not supported: cannot convert argument 1 from 'const std::initializer_list<_Ty>' to 'vk::ArrayProxyNoTemporaries<const int32_t>'
// fct( getInitializerList() ); // not supported: cannot convert argument 1 from 'std::initializer_list<_Ty>' to 'vk::ArrayProxyNoTemporaries<int>'
// fctc( getInitializerList() ); // not supported: cannot convert argument 1 from 'std::initializer_list<_Ty>' to 'vk::ArrayProxyNoTemporaries<const int32_t>'
// vk::ArrayProxyNoTemporaries<int> apnt22 = il1; // not supported: cannot convert from 'std::initializer_list<_Ty>' to 'vk::ArrayProxyNoTemporaries<int>'
// vk::ArrayProxyNoTemporaries<int> apnt23 = il2; // not supported: cannot convert from 'std::initializer_list<const int>' to 'vk::ArrayProxyNoTemporaries<int>'
// vk::ArrayProxyNoTemporaries<int> apnt24 = il3; // not supported: cannot convert from 'const std::initializer_list<_Ty>' to 'vk::ArrayProxyNoTemporaries<int>'
// vk::ArrayProxyNoTemporaries<int> apnt25 = il4; // not supported: cannot convert from 'const std::initializer_list<const int>' to 'vk::ArrayProxyNoTemporaries<int>'
vk : : ArrayProxyNoTemporaries < const int > apnt26 = { } ;
assert ( apnt26 . size ( ) = = 0 ) ;
// vk::ArrayProxyNoTemporaries<const int> apnt27 = { 0, 1 }; // not supported: cannot convert from 'initializer list' to 'vk::ArrayProxyNoTemporaries<const int32_t>'
vk : : ArrayProxyNoTemporaries < const int > apnt28 = il1 ;
assert ( apnt28 . size ( ) = = 2 ) ;
vk : : ArrayProxyNoTemporaries < const int > apnt29 = il2 ;
assert ( apnt29 . size ( ) = = 2 ) ;
vk : : ArrayProxyNoTemporaries < const int > apnt30 = il3 ;
assert ( apnt30 . size ( ) = = 2 ) ;
vk : : ArrayProxyNoTemporaries < const int > apnt31 = il4 ;
assert ( apnt31 . size ( ) = = 2 ) ;
2021-01-14 10:41:30 +00:00
}
2022-02-28 09:11:04 +00:00
catch ( vk : : SystemError const & err )
2021-01-14 10:41:30 +00:00
{
std : : cout < < " vk::SystemError: " < < err . what ( ) < < std : : endl ;
2022-02-28 09:11:04 +00:00
exit ( - 1 ) ;
2021-01-14 10:41:30 +00:00
}
2022-02-28 09:11:04 +00:00
catch ( . . . )
2021-01-14 10:41:30 +00:00
{
std : : cout < < " unknown error \n " ;
2022-02-28 09:11:04 +00:00
exit ( - 1 ) ;
2021-01-14 10:41:30 +00:00
}
return 0 ;
}