diff --git a/snippets/ArrayWrapper1D.hpp b/snippets/ArrayWrapper1D.hpp index 97a5f51..1a9fd43 100644 --- a/snippets/ArrayWrapper1D.hpp +++ b/snippets/ArrayWrapper1D.hpp @@ -57,66 +57,72 @@ public: } #endif -#if defined( VULKAN_HPP_HAS_SPACESHIP_OPERATOR ) - template ::value, int>::type = 0> - std::strong_ordering operator<=>( ArrayWrapper1D const & rhs ) const VULKAN_HPP_NOEXCEPT - { - return *static_cast const *>( this ) <=> *static_cast const *>( &rhs ); - } -#else - template ::value, int>::type = 0> - bool operator<( ArrayWrapper1D const & rhs ) const VULKAN_HPP_NOEXCEPT - { - return *static_cast const *>( this ) < *static_cast const *>( &rhs ); - } - - template ::value, int>::type = 0> - bool operator<=( ArrayWrapper1D const & rhs ) const VULKAN_HPP_NOEXCEPT - { - return *static_cast const *>( this ) <= *static_cast const *>( &rhs ); - } - - template ::value, int>::type = 0> - bool operator>( ArrayWrapper1D const & rhs ) const VULKAN_HPP_NOEXCEPT - { - return *static_cast const *>( this ) > *static_cast const *>( &rhs ); - } - - template ::value, int>::type = 0> - bool operator>=( ArrayWrapper1D const & rhs ) const VULKAN_HPP_NOEXCEPT - { - return *static_cast const *>( this ) >= *static_cast const *>( &rhs ); - } -#endif - - template ::value, int>::type = 0> - bool operator==( ArrayWrapper1D const & rhs ) const VULKAN_HPP_NOEXCEPT - { - return *static_cast const *>( this ) == *static_cast const *>( &rhs ); - } - - template ::value, int>::type = 0> - bool operator!=( ArrayWrapper1D const & rhs ) const VULKAN_HPP_NOEXCEPT - { - return *static_cast const *>( this ) != *static_cast const *>( &rhs ); - } - private: VULKAN_HPP_CONSTEXPR_14 void copy( char const * data, size_t len ) VULKAN_HPP_NOEXCEPT { - size_t n = std::min( N, len ); + size_t n = std::min( N - 1, len ); for ( size_t i = 0; i < n; ++i ) { ( *this )[i] = data[i]; } - for ( size_t i = n; i < N; ++i ) - { - ( *this )[i] = 0; - } + ( *this )[n] = 0; } }; +// relational operators between ArrayWrapper1D of chars with potentially different sizes +#if defined( VULKAN_HPP_HAS_SPACESHIP_OPERATOR ) +template +std::strong_ordering operator<=>( ArrayWrapper1D const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT +{ + int result = strcmp( lhs.data(), rhs.data() ); + return ( result < 0 ) ? std::strong_ordering::less : ( ( result > 0 ) ? std::strong_ordering::greater : std::strong_ordering::equal ); +} +#else +template +bool operator<( ArrayWrapper1D const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT +{ + return strcmp( lhs.data(), rhs.data() ) < 0; +} + +template +bool operator<=( ArrayWrapper1D const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT +{ + return strcmp( lhs.data(), rhs.data() ) <= 0; +} + +template +bool operator>( ArrayWrapper1D const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT +{ + return strcmp( lhs.data(), rhs.data() ) > 0; +} + +template +bool operator>=( ArrayWrapper1D const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT +{ + return strcmp( lhs.data(), rhs.data() ) >= 0; +} +#endif + +template +bool operator==( ArrayWrapper1D const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT +{ + return strcmp( lhs.data(), rhs.data() ) == 0; +} + +template +bool operator!=( ArrayWrapper1D const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT +{ + return strcmp( lhs.data(), rhs.data() ) != 0; +} + // specialization of relational operators between std::string and arrays of chars +#if defined( VULKAN_HPP_HAS_SPACESHIP_OPERATOR ) +template +std::strong_ordering operator<=>( std::string const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT +{ + return lhs <=> rhs.data(); +} +#else template bool operator<( std::string const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT { @@ -140,6 +146,7 @@ bool operator>=( std::string const & lhs, ArrayWrapper1D const & rhs ) { return lhs >= rhs.data(); } +#endif template bool operator==( std::string const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT diff --git a/tests/ArrayWrapper/ArrayWrapper.cpp b/tests/ArrayWrapper/ArrayWrapper.cpp index 1a32fe6..a44cc64 100644 --- a/tests/ArrayWrapper/ArrayWrapper.cpp +++ b/tests/ArrayWrapper/ArrayWrapper.cpp @@ -26,39 +26,44 @@ void f( std::string const & s ) int main( int /*argc*/, char ** /*argv*/ ) { - vk::ArrayWrapper1D aw1( { 'f', 'o', 'o', 'b', 'a', 'h' } ); - std::string s1 = aw1; + vk::ArrayWrapper1D awc1( { 'f', 'o', 'o', 'b', 'a', 'h' } ); + std::string s1 = awc1; assert( s1.length() == 6 ); - std::cout << "<" << aw1 << ">" << std::endl; + std::cout << "<" << awc1 << ">" << std::endl; - // s1 = aw1; // 'operator =' is ambiguous + // s1 = awc1; // 'operator =' is ambiguous std::string foobah = "foobah"; - vk::ArrayWrapper1D aw2( foobah ); - f( aw2 ); + vk::ArrayWrapper1D awc2( foobah ); + f( awc2 ); - vk::ArrayWrapper1D aw3( { 'f', 'o', 'o', 'b', 'a', 'h' } ); - std::string s3 = aw3; - assert( s3.length() == 5 ); + vk::ArrayWrapper1D awc3( { 'f', 'o', 'o', 'b', 'a', 'h' } ); + std::string s3 = awc3; + assert( s3.length() == 4 ); std::cout << "<" << s3 << ">" << std::endl; - vk::ArrayWrapper1D aw4( foobah ); - std::string s4 = aw4; - assert( s4.length() == 5 ); + vk::ArrayWrapper1D awc4( foobah ); + std::string s4 = awc4; + assert( s4.length() == 4 ); #if 17 <= VULKAN_HPP_CPP_VERSION std::cout << std::boolalpha << std::is_convertible_v, std::string_view> << std::endl; - std::string_view sv1 = aw1; + std::string_view sv1 = awc1; assert( sv1.size() == 6 ); - sv1 = aw2; + sv1 = awc2; assert( sv1.size() == 6 ); - sv1 = aw3; + sv1 = awc3; assert( sv1.size() == 5 ); - vk::ArrayWrapper1D aw5( sv1 ); + vk::ArrayWrapper1D awc5( sv1 ); #endif + assert( awc1 == awc2 ); + assert( awc3 == awc4 ); + assert( foobah == awc2 ); + assert( foobah > awc4 ); + return 0; } diff --git a/vulkan/vulkan.hpp b/vulkan/vulkan.hpp index 3157f99..a4da92f 100644 --- a/vulkan/vulkan.hpp +++ b/vulkan/vulkan.hpp @@ -146,66 +146,72 @@ namespace VULKAN_HPP_NAMESPACE } #endif -#if defined( VULKAN_HPP_HAS_SPACESHIP_OPERATOR ) - template ::value, int>::type = 0> - std::strong_ordering operator<=>( ArrayWrapper1D const & rhs ) const VULKAN_HPP_NOEXCEPT - { - return *static_cast const *>( this ) <=> *static_cast const *>( &rhs ); - } -#else - template ::value, int>::type = 0> - bool operator<( ArrayWrapper1D const & rhs ) const VULKAN_HPP_NOEXCEPT - { - return *static_cast const *>( this ) < *static_cast const *>( &rhs ); - } - - template ::value, int>::type = 0> - bool operator<=( ArrayWrapper1D const & rhs ) const VULKAN_HPP_NOEXCEPT - { - return *static_cast const *>( this ) <= *static_cast const *>( &rhs ); - } - - template ::value, int>::type = 0> - bool operator>( ArrayWrapper1D const & rhs ) const VULKAN_HPP_NOEXCEPT - { - return *static_cast const *>( this ) > *static_cast const *>( &rhs ); - } - - template ::value, int>::type = 0> - bool operator>=( ArrayWrapper1D const & rhs ) const VULKAN_HPP_NOEXCEPT - { - return *static_cast const *>( this ) >= *static_cast const *>( &rhs ); - } -#endif - - template ::value, int>::type = 0> - bool operator==( ArrayWrapper1D const & rhs ) const VULKAN_HPP_NOEXCEPT - { - return *static_cast const *>( this ) == *static_cast const *>( &rhs ); - } - - template ::value, int>::type = 0> - bool operator!=( ArrayWrapper1D const & rhs ) const VULKAN_HPP_NOEXCEPT - { - return *static_cast const *>( this ) != *static_cast const *>( &rhs ); - } - private: VULKAN_HPP_CONSTEXPR_14 void copy( char const * data, size_t len ) VULKAN_HPP_NOEXCEPT { - size_t n = std::min( N, len ); + size_t n = std::min( N - 1, len ); for ( size_t i = 0; i < n; ++i ) { ( *this )[i] = data[i]; } - for ( size_t i = n; i < N; ++i ) - { - ( *this )[i] = 0; - } + ( *this )[n] = 0; } }; - // specialization of relational operators between std::string and arrays of chars +// relational operators between ArrayWrapper1D of chars with potentially different sizes +#if defined( VULKAN_HPP_HAS_SPACESHIP_OPERATOR ) + template + std::strong_ordering operator<=>( ArrayWrapper1D const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT + { + int result = strcmp( lhs.data(), rhs.data() ); + return ( result < 0 ) ? std::strong_ordering::less : ( ( result > 0 ) ? std::strong_ordering::greater : std::strong_ordering::equal ); + } +#else + template + bool operator<( ArrayWrapper1D const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT + { + return strcmp( lhs.data(), rhs.data() ) < 0; + } + + template + bool operator<=( ArrayWrapper1D const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT + { + return strcmp( lhs.data(), rhs.data() ) <= 0; + } + + template + bool operator>( ArrayWrapper1D const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT + { + return strcmp( lhs.data(), rhs.data() ) > 0; + } + + template + bool operator>=( ArrayWrapper1D const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT + { + return strcmp( lhs.data(), rhs.data() ) >= 0; + } +#endif + + template + bool operator==( ArrayWrapper1D const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT + { + return strcmp( lhs.data(), rhs.data() ) == 0; + } + + template + bool operator!=( ArrayWrapper1D const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT + { + return strcmp( lhs.data(), rhs.data() ) != 0; + } + +// specialization of relational operators between std::string and arrays of chars +#if defined( VULKAN_HPP_HAS_SPACESHIP_OPERATOR ) + template + std::strong_ordering operator<=>( std::string const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT + { + return lhs <=> rhs.data(); + } +#else template bool operator<( std::string const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT { @@ -229,6 +235,7 @@ namespace VULKAN_HPP_NAMESPACE { return lhs >= rhs.data(); } +#endif template bool operator==( std::string const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT diff --git a/vulkan/vulkansc.hpp b/vulkan/vulkansc.hpp index ec9b543..8a44ad2 100644 --- a/vulkan/vulkansc.hpp +++ b/vulkan/vulkansc.hpp @@ -146,66 +146,72 @@ namespace VULKAN_HPP_NAMESPACE } #endif -#if defined( VULKAN_HPP_HAS_SPACESHIP_OPERATOR ) - template ::value, int>::type = 0> - std::strong_ordering operator<=>( ArrayWrapper1D const & rhs ) const VULKAN_HPP_NOEXCEPT - { - return *static_cast const *>( this ) <=> *static_cast const *>( &rhs ); - } -#else - template ::value, int>::type = 0> - bool operator<( ArrayWrapper1D const & rhs ) const VULKAN_HPP_NOEXCEPT - { - return *static_cast const *>( this ) < *static_cast const *>( &rhs ); - } - - template ::value, int>::type = 0> - bool operator<=( ArrayWrapper1D const & rhs ) const VULKAN_HPP_NOEXCEPT - { - return *static_cast const *>( this ) <= *static_cast const *>( &rhs ); - } - - template ::value, int>::type = 0> - bool operator>( ArrayWrapper1D const & rhs ) const VULKAN_HPP_NOEXCEPT - { - return *static_cast const *>( this ) > *static_cast const *>( &rhs ); - } - - template ::value, int>::type = 0> - bool operator>=( ArrayWrapper1D const & rhs ) const VULKAN_HPP_NOEXCEPT - { - return *static_cast const *>( this ) >= *static_cast const *>( &rhs ); - } -#endif - - template ::value, int>::type = 0> - bool operator==( ArrayWrapper1D const & rhs ) const VULKAN_HPP_NOEXCEPT - { - return *static_cast const *>( this ) == *static_cast const *>( &rhs ); - } - - template ::value, int>::type = 0> - bool operator!=( ArrayWrapper1D const & rhs ) const VULKAN_HPP_NOEXCEPT - { - return *static_cast const *>( this ) != *static_cast const *>( &rhs ); - } - private: VULKAN_HPP_CONSTEXPR_14 void copy( char const * data, size_t len ) VULKAN_HPP_NOEXCEPT { - size_t n = std::min( N, len ); + size_t n = std::min( N - 1, len ); for ( size_t i = 0; i < n; ++i ) { ( *this )[i] = data[i]; } - for ( size_t i = n; i < N; ++i ) - { - ( *this )[i] = 0; - } + ( *this )[n] = 0; } }; - // specialization of relational operators between std::string and arrays of chars +// relational operators between ArrayWrapper1D of chars with potentially different sizes +#if defined( VULKAN_HPP_HAS_SPACESHIP_OPERATOR ) + template + std::strong_ordering operator<=>( ArrayWrapper1D const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT + { + int result = strcmp( lhs.data(), rhs.data() ); + return ( result < 0 ) ? std::strong_ordering::less : ( ( result > 0 ) ? std::strong_ordering::greater : std::strong_ordering::equal ); + } +#else + template + bool operator<( ArrayWrapper1D const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT + { + return strcmp( lhs.data(), rhs.data() ) < 0; + } + + template + bool operator<=( ArrayWrapper1D const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT + { + return strcmp( lhs.data(), rhs.data() ) <= 0; + } + + template + bool operator>( ArrayWrapper1D const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT + { + return strcmp( lhs.data(), rhs.data() ) > 0; + } + + template + bool operator>=( ArrayWrapper1D const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT + { + return strcmp( lhs.data(), rhs.data() ) >= 0; + } +#endif + + template + bool operator==( ArrayWrapper1D const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT + { + return strcmp( lhs.data(), rhs.data() ) == 0; + } + + template + bool operator!=( ArrayWrapper1D const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT + { + return strcmp( lhs.data(), rhs.data() ) != 0; + } + +// specialization of relational operators between std::string and arrays of chars +#if defined( VULKAN_HPP_HAS_SPACESHIP_OPERATOR ) + template + std::strong_ordering operator<=>( std::string const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT + { + return lhs <=> rhs.data(); + } +#else template bool operator<( std::string const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT { @@ -229,6 +235,7 @@ namespace VULKAN_HPP_NAMESPACE { return lhs >= rhs.data(); } +#endif template bool operator==( std::string const & lhs, ArrayWrapper1D const & rhs ) VULKAN_HPP_NOEXCEPT