From fa0c6b7179c062b7ca92d120455ce02a9f4e9e19 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Wed, 18 Dec 2024 17:12:13 +0100 Subject: [PATCH] refactor: Remove unused Span alias Also, fixup some wording. --- src/cluster_linearize.h | 2 +- src/crypto/poly1305.h | 2 +- src/random.h | 4 ++-- src/script/miniscript.h | 2 +- src/span.h | 45 +++++++++++++++-------------------------- src/test/span_tests.cpp | 4 ++-- 6 files changed, 23 insertions(+), 36 deletions(-) diff --git a/src/cluster_linearize.h b/src/cluster_linearize.h index bef29a0f900..7c7401706f6 100644 --- a/src/cluster_linearize.h +++ b/src/cluster_linearize.h @@ -75,7 +75,7 @@ public: * * @param depgraph The original DepGraph that is being remapped. * - * @param mapping A std::span such that mapping[i] gives the position in the new DepGraph + * @param mapping A span such that mapping[i] gives the position in the new DepGraph * for position i in the old depgraph. Its size must be equal to * depgraph.PositionRange(). The value of mapping[i] is ignored if * position i is a hole in depgraph (i.e., if !depgraph.Positions()[i]). diff --git a/src/crypto/poly1305.h b/src/crypto/poly1305.h index cfcb498761f..46a83e6a190 100644 --- a/src/crypto/poly1305.h +++ b/src/crypto/poly1305.h @@ -33,7 +33,7 @@ void poly1305_finish(poly1305_context *st, unsigned char mac[16]) noexcept; } // namespace poly1305_donna -/** C++ wrapper with std::byte std::span interface around poly1305_donna code. */ +/** C++ wrapper with std::byte span interface around poly1305_donna code. */ class Poly1305 { poly1305_donna::poly1305_context m_ctx; diff --git a/src/random.h b/src/random.h index 2bfbb4ab8e5..fc48fdbe54f 100644 --- a/src/random.h +++ b/src/random.h @@ -263,7 +263,7 @@ public: } } - /** Fill a std::span with random bytes. */ + /** Fill a span with random bytes. */ void fillrand(std::span span) noexcept { while (span.size() >= 8) { @@ -400,7 +400,7 @@ public: return ReadLE64(buf.data()); } - /** Fill a byte std::span with random bytes. This overrides the RandomMixin version. */ + /** Fill a byte span with random bytes. This overrides the RandomMixin version. */ void fillrand(std::span output) noexcept; }; diff --git a/src/script/miniscript.h b/src/script/miniscript.h index 02702303aee..450a3d56451 100644 --- a/src/script/miniscript.h +++ b/src/script/miniscript.h @@ -593,7 +593,7 @@ private: * child. It can modify the state. Children of a given node will have downfn() * called in order. * - upfn is a callable (State&&, const Node&, std::span) -> std::optional, - * which given a node, its state, and a std::span of the results of its children, + * which given a node, its state, and a span of the results of its children, * computes the result of the node. If std::nullopt is returned by upfn, * TreeEvalMaybe() immediately returns std::nullopt. * The return value of TreeEvalMaybe is the result of the root node. diff --git a/src/span.h b/src/span.h index 7f3cb74f745..fe9fdc3e6c8 100644 --- a/src/span.h +++ b/src/span.h @@ -11,38 +11,38 @@ #include #include -/** A Span is an object that can refer to a contiguous sequence of objects. +/** A span is an object that can refer to a contiguous sequence of objects. * - * Things to be aware of when writing code that deals with Spans: + * Things to be aware of when writing code that deals with spans: * - * - Similar to references themselves, Spans are subject to reference lifetime + * - Similar to references themselves, spans are subject to reference lifetime * issues. The user is responsible for making sure the objects pointed to by - * a Span live as long as the Span is used. For example: + * a span live as long as the span is used. For example: * * std::vector vec{1,2,3,4}; - * Span sp(vec); + * std::span sp(vec); * vec.push_back(5); * printf("%i\n", sp.front()); // UB! * * may exhibit undefined behavior, as increasing the size of a vector may * invalidate references. * - * - One particular pitfall is that Spans can be constructed from temporaries, - * but this is unsafe when the Span is stored in a variable, outliving the + * - One particular pitfall is that spans can be constructed from temporaries, + * but this is unsafe when the span is stored in a variable, outliving the * temporary. For example, this will compile, but exhibits undefined behavior: * - * Span sp(std::vector{1, 2, 3}); + * std::span sp(std::vector{1, 2, 3}); * printf("%i\n", sp.front()); // UB! * * The lifetime of the vector ends when the statement it is created in ends. - * Thus the Span is left with a dangling reference, and using it is undefined. + * Thus the span is left with a dangling reference, and using it is undefined. * - * - Due to Span's automatic creation from range-like objects (arrays, and data + * - Due to spans automatic creation from range-like objects (arrays, and data * types that expose a data() and size() member function), functions that - * accept a Span as input parameter can be called with any compatible + * accept a span as input parameter can be called with any compatible * range-like object. For example, this works: * - * void Foo(Span arg); + * void Foo(std::span arg); * * Foo(std::vector{1, 2, 3}); // Works * @@ -50,10 +50,10 @@ * container, and only about having exactly a range of elements. However it * may also be surprising to see automatic conversions in this case. * - * When a function accepts a Span with a mutable element type, it will not + * When a function accepts a span with a mutable element type, it will not * accept temporaries; only variables or other references. For example: * - * void FooMut(Span arg); + * void FooMut(std::span arg); * * FooMut(std::vector{1, 2, 3}); // Does not compile * std::vector baz{1, 2, 3}; @@ -69,7 +69,6 @@ * result will be present in that variable after the call. Passing a temporary * is useless in that context. */ -#define Span std::span /** Pop the last element off a span, and return a reference to that element. */ template @@ -81,18 +80,6 @@ T& SpanPopBack(std::span& span) return back; } -// From C++20 as_bytes and as_writeable_bytes -template -Span AsBytes(Span s) noexcept -{ - return {reinterpret_cast(s.data()), s.size_bytes()}; -} -template -Span AsWritableBytes(Span s) noexcept -{ - return {reinterpret_cast(s.data()), s.size_bytes()}; -} - template auto MakeByteSpan(const V& v) noexcept { @@ -117,10 +104,10 @@ inline const unsigned char* UCharCast(const std::byte* c) { return reinterpret_c template concept BasicByte = requires { UCharCast(std::span{}.data()); }; -// Helper function to safely convert a Span to a Span<[const] unsigned char>. +// Helper function to safely convert a span to a span<[const] unsigned char>. template constexpr auto UCharSpanCast(std::span s) { return std::span, N>{UCharCast(s.data()), s.size()}; } -/** Like the Span constructor, but for (const) unsigned char member types only. Only works for (un)signed char containers. */ +/** Like the std::span constructor, but for (const) unsigned char member types only. Only works for (un)signed char containers. */ template constexpr auto MakeUCharSpan(const V& v) -> decltype(UCharSpanCast(std::span{v})) { return UCharSpanCast(std::span{v}); } template constexpr auto MakeWritableUCharSpan(V&& v) -> decltype(UCharSpanCast(std::span{std::forward(v)})) { return UCharSpanCast(std::span{std::forward(v)}); } diff --git a/src/test/span_tests.cpp b/src/test/span_tests.cpp index caab1f30571..da088429557 100644 --- a/src/test/span_tests.cpp +++ b/src/test/span_tests.cpp @@ -44,9 +44,9 @@ BOOST_AUTO_TEST_SUITE(span_tests) // Make sure template std::span template deduction guides accurately enable calls to // std::span constructor overloads that work, and disable calls to constructor overloads that -// don't work. This makes it is possible to use the std::span constructor in a SFINAE +// don't work. This makes it possible to use the std::span constructor in a SFINAE // contexts like in the Spannable function above to detect whether types are or -// aren't compatible with Spans at compile time. +// aren't compatible with std::span at compile time. BOOST_AUTO_TEST_CASE(span_constructor_sfinae) { BOOST_CHECK(Spannable(std::vector{}));