refactor: test: Return std::span from StringBytes

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<const char>(<brace-enclosed initializer list>)’
 ...
 /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<const char>({str.data(), str.size()});
       |            ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
This commit is contained in:
MarcoFalke 2024-12-18 15:36:27 +01:00
parent fa86223475
commit faa5391f77
No known key found for this signature in database

View file

@ -34,9 +34,9 @@ inline std::ostream& operator<<(std::ostream& os, const std::pair<const Serializ
namespace wallet { namespace wallet {
static Span<const std::byte> StringBytes(std::string_view str) inline std::span<const std::byte> StringBytes(std::string_view str)
{ {
return AsBytes<const char>({str.data(), str.size()}); return std::as_bytes(std::span{str});
} }
static SerializeData StringData(std::string_view str) static SerializeData StringData(std::string_view str)