mirror of
https://github.com/KhronosGroup/Vulkan-Hpp.git
synced 2024-10-14 16:32:17 +00:00
Fix ArrayWrapper1D::operator std::string() and ArrayWrapper1D::operator std::string_view() to return a string/string_view of the correct length. (#1725)
This commit is contained in:
parent
4cb522cc51
commit
9bece47d4c
@ -46,14 +46,14 @@ public:
|
|||||||
template <typename B = T, typename std::enable_if<std::is_same<B, char>::value, int>::type = 0>
|
template <typename B = T, typename std::enable_if<std::is_same<B, char>::value, int>::type = 0>
|
||||||
operator std::string() const
|
operator std::string() const
|
||||||
{
|
{
|
||||||
return std::string( this->data(), N );
|
return std::string( this->data(), strnlen( this->data(), N ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 17 <= VULKAN_HPP_CPP_VERSION
|
#if 17 <= VULKAN_HPP_CPP_VERSION
|
||||||
template <typename B = T, typename std::enable_if<std::is_same<B, char>::value, int>::type = 0>
|
template <typename B = T, typename std::enable_if<std::is_same<B, char>::value, int>::type = 0>
|
||||||
operator std::string_view() const
|
operator std::string_view() const
|
||||||
{
|
{
|
||||||
return std::string_view( this->data(), N );
|
return std::string_view( this->data(), strnlen( this->data(), N ) );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array> // ArrayWrapperND
|
#include <array> // ArrayWrapperND
|
||||||
#include <string> // std::string
|
#include <string> // std::string
|
||||||
|
#include <string.h> // strnlen
|
||||||
#include <vulkan/${vulkan_h}>
|
#include <vulkan/${vulkan_h}>
|
||||||
#include <vulkan/vulkan_hpp_macros.hpp>
|
#include <vulkan/vulkan_hpp_macros.hpp>
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ int main( int /*argc*/, char ** /*argv*/ )
|
|||||||
{
|
{
|
||||||
vk::ArrayWrapper1D<char, 10> aw1( { 'f', 'o', 'o', 'b', 'a', 'h' } );
|
vk::ArrayWrapper1D<char, 10> aw1( { 'f', 'o', 'o', 'b', 'a', 'h' } );
|
||||||
std::string s1 = aw1;
|
std::string s1 = aw1;
|
||||||
assert( s1.length() == 10 );
|
assert( s1.length() == 6 );
|
||||||
std::cout << "<" << aw1 << ">" << std::endl;
|
std::cout << "<" << aw1 << ">" << std::endl;
|
||||||
|
|
||||||
// s1 = aw1; // 'operator =' is ambiguous
|
// s1 = aw1; // 'operator =' is ambiguous
|
||||||
@ -51,9 +51,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
|||||||
std::cout << std::boolalpha << std::is_convertible_v<vk::ArrayWrapper1D<char, 10>, std::string_view> << std::endl;
|
std::cout << std::boolalpha << std::is_convertible_v<vk::ArrayWrapper1D<char, 10>, std::string_view> << std::endl;
|
||||||
|
|
||||||
std::string_view sv1 = aw1;
|
std::string_view sv1 = aw1;
|
||||||
assert( sv1.size() == 10 );
|
assert( sv1.size() == 6 );
|
||||||
sv1 = aw2;
|
sv1 = aw2;
|
||||||
assert( sv1.size() == 20 );
|
assert( sv1.size() == 6 );
|
||||||
sv1 = aw3;
|
sv1 = aw3;
|
||||||
assert( sv1.size() == 5 );
|
assert( sv1.size() == 5 );
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array> // ArrayWrapperND
|
#include <array> // ArrayWrapperND
|
||||||
|
#include <string.h> // strnlen
|
||||||
#include <string> // std::string
|
#include <string> // std::string
|
||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
#include <vulkan/vulkan_hpp_macros.hpp>
|
#include <vulkan/vulkan_hpp_macros.hpp>
|
||||||
@ -134,14 +135,14 @@ namespace VULKAN_HPP_NAMESPACE
|
|||||||
template <typename B = T, typename std::enable_if<std::is_same<B, char>::value, int>::type = 0>
|
template <typename B = T, typename std::enable_if<std::is_same<B, char>::value, int>::type = 0>
|
||||||
operator std::string() const
|
operator std::string() const
|
||||||
{
|
{
|
||||||
return std::string( this->data(), N );
|
return std::string( this->data(), strnlen( this->data(), N ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 17 <= VULKAN_HPP_CPP_VERSION
|
#if 17 <= VULKAN_HPP_CPP_VERSION
|
||||||
template <typename B = T, typename std::enable_if<std::is_same<B, char>::value, int>::type = 0>
|
template <typename B = T, typename std::enable_if<std::is_same<B, char>::value, int>::type = 0>
|
||||||
operator std::string_view() const
|
operator std::string_view() const
|
||||||
{
|
{
|
||||||
return std::string_view( this->data(), N );
|
return std::string_view( this->data(), strnlen( this->data(), N ) );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array> // ArrayWrapperND
|
#include <array> // ArrayWrapperND
|
||||||
|
#include <string.h> // strnlen
|
||||||
#include <string> // std::string
|
#include <string> // std::string
|
||||||
#include <vulkan/vulkan_hpp_macros.hpp>
|
#include <vulkan/vulkan_hpp_macros.hpp>
|
||||||
#include <vulkan/vulkan_sc_core.h>
|
#include <vulkan/vulkan_sc_core.h>
|
||||||
@ -134,14 +135,14 @@ namespace VULKAN_HPP_NAMESPACE
|
|||||||
template <typename B = T, typename std::enable_if<std::is_same<B, char>::value, int>::type = 0>
|
template <typename B = T, typename std::enable_if<std::is_same<B, char>::value, int>::type = 0>
|
||||||
operator std::string() const
|
operator std::string() const
|
||||||
{
|
{
|
||||||
return std::string( this->data(), N );
|
return std::string( this->data(), strnlen( this->data(), N ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 17 <= VULKAN_HPP_CPP_VERSION
|
#if 17 <= VULKAN_HPP_CPP_VERSION
|
||||||
template <typename B = T, typename std::enable_if<std::is_same<B, char>::value, int>::type = 0>
|
template <typename B = T, typename std::enable_if<std::is_same<B, char>::value, int>::type = 0>
|
||||||
operator std::string_view() const
|
operator std::string_view() const
|
||||||
{
|
{
|
||||||
return std::string_view( this->data(), N );
|
return std::string_view( this->data(), strnlen( this->data(), N ) );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user