Skip to content

Commit faa5391

Browse files
author
MarcoFalke
committed
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()}); | ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
1 parent fa86223 commit faa5391

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/wallet/test/db_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ inline std::ostream& operator<<(std::ostream& os, const std::pair<const Serializ
3434

3535
namespace wallet {
3636

37-
static Span<const std::byte> StringBytes(std::string_view str)
37+
inline std::span<const std::byte> StringBytes(std::string_view str)
3838
{
39-
return AsBytes<const char>({str.data(), str.size()});
39+
return std::as_bytes(std::span{str});
4040
}
4141

4242
static SerializeData StringData(std::string_view str)

0 commit comments

Comments
 (0)