Add cast operator to reference of UniqueHandle of ResultValue<UniqueHandle>.

This commit is contained in:
asuessenbach
2020-06-17 10:10:57 +02:00
parent e83bd40ab5
commit 3724bfd0f5
5 changed files with 49 additions and 48 deletions

View File

@@ -26,13 +26,9 @@ set(SOURCES
source_group(headers FILES ${HEADERS})
source_group(sources FILES ${SOURCES})
add_library(ResultValue
add_executable(ResultValue
${HEADERS}
${SOURCES}
)
if (UNIX)
target_link_libraries(ResultValue "-ldl")
endif()
set_target_properties(ResultValue PROPERTIES FOLDER "Tests")

View File

@@ -21,34 +21,47 @@
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE
// Compile only test for issue 589.
void test_conversion()
{
#if defined(VULKAN_DISABLE_IMPLICIT_RESULT_VALUE_CAST)
static_assert(false, "Conversions not enabled");
#endif
void as_value( int ) {}
void as_ref( int & ) {}
void as_rvref( int && ) {}
void as_cref( const int & ) {}
void as_crvref( const int && ) {}
void as_value(int);
void as_ref(int&);
void as_cref(const int&);
void as_rvref(int&&);
void as_crvref(const int&&);
void as_cref( const vk::UniquePipeline & ) {}
int main( int /*argc*/, char ** /*argv*/ )
{
#if defined( VULKAN_DISABLE_IMPLICIT_RESULT_VALUE_CAST )
static_assert( false, "Conversions not enabled" );
#endif
using result = vk::ResultValue<int>;
auto val = result {vk::Result{}, 42};
const auto cval = result {vk::Result{}, 42};
auto val = result{ vk::Result{}, 42 };
const auto cval = result{ vk::Result{}, 42 };
as_value(val);
as_value(cval);
as_value( val );
as_value( cval );
as_ref(val);
//as_ref(cval); // should fail
as_cref(val);
as_cref(cval);
as_ref( val );
// as_ref(cval); // should fail
as_cref( val );
as_cref( cval );
as_rvref(std::move(val));
//as_rvref(std::move(cval)); // should fail
as_crvref(std::move(val));
as_crvref(std::move(cval));
as_rvref( std::move( val ) );
// as_rvref(std::move(cval)); // should fail
as_crvref( std::move( val ) );
as_crvref( std::move( cval ) );
vk::Pipeline pipe( VkPipeline( 0x8 ) ); // fake a Pipeline here, to have something different from zero
vk::UniquePipeline pipeline( pipe );
vk::ResultValue<vk::UniquePipeline> rv( {}, std::move( pipeline ) );
as_cref( rv ); // does not move out handle
assert( rv.value );
auto p = std::move( rv.value );
p.release(); // release the faked Pipeline, to prevent error on trying to destroy it
return 0;
}