From faa5391f77037601875cf4ed154bc42840d34b12 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Wed, 18 Dec 2024 15:36:27 +0100 Subject: [PATCH] refactor: test: Return std::span from StringBytes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is possible and safe, because std::span can implicitly convert into Span, if needed. Changing this function is required, because std::span requires the extent template parameter to be specified as well. Instead of explicilty specifying them, just let the compiler derive the template parameters correctly. Otherwise, there would be a compile error later on: src/wallet/test/db_tests.cpp:39:37: error: no matching function for call to ‘as_bytes()’ ... /usr/include/c++/11/span:420:5: note: candidate: ... | as_bytes(span<_Type, _Extent> __sp) noexcept | ^~~~~~~~ /usr/include/c++/11/span:420:5: note: template argument deduction/substitution failed: src/wallet/test/db_tests.cpp:39:37: note: couldn’t deduce template parameter ‘_Extent’ | return std::as_bytes({str.data(), str.size()}); | ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ --- src/wallet/test/db_tests.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/test/db_tests.cpp b/src/wallet/test/db_tests.cpp index ea32199497..41951e84c8 100644 --- a/src/wallet/test/db_tests.cpp +++ b/src/wallet/test/db_tests.cpp @@ -34,9 +34,9 @@ inline std::ostream& operator<<(std::ostream& os, const std::pair StringBytes(std::string_view str) +inline std::span StringBytes(std::string_view str) { - return AsBytes({str.data(), str.size()}); + return std::as_bytes(std::span{str}); } static SerializeData StringData(std::string_view str)