Skip to content

Commit fa0c6b7

Browse files
author
MarcoFalke
committed
refactor: Remove unused Span alias
Also, fixup some wording.
1 parent fade0b5 commit fa0c6b7

File tree

6 files changed

+23
-36
lines changed

6 files changed

+23
-36
lines changed

src/cluster_linearize.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class DepGraph
7575
*
7676
* @param depgraph The original DepGraph that is being remapped.
7777
*
78-
* @param mapping A std::span such that mapping[i] gives the position in the new DepGraph
78+
* @param mapping A span such that mapping[i] gives the position in the new DepGraph
7979
* for position i in the old depgraph. Its size must be equal to
8080
* depgraph.PositionRange(). The value of mapping[i] is ignored if
8181
* position i is a hole in depgraph (i.e., if !depgraph.Positions()[i]).

src/crypto/poly1305.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void poly1305_finish(poly1305_context *st, unsigned char mac[16]) noexcept;
3333

3434
} // namespace poly1305_donna
3535

36-
/** C++ wrapper with std::byte std::span interface around poly1305_donna code. */
36+
/** C++ wrapper with std::byte span interface around poly1305_donna code. */
3737
class Poly1305
3838
{
3939
poly1305_donna::poly1305_context m_ctx;

src/random.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class RandomMixin
263263
}
264264
}
265265

266-
/** Fill a std::span with random bytes. */
266+
/** Fill a span with random bytes. */
267267
void fillrand(std::span<std::byte> span) noexcept
268268
{
269269
while (span.size() >= 8) {
@@ -400,7 +400,7 @@ class FastRandomContext : public RandomMixin<FastRandomContext>
400400
return ReadLE64(buf.data());
401401
}
402402

403-
/** Fill a byte std::span with random bytes. This overrides the RandomMixin version. */
403+
/** Fill a byte span with random bytes. This overrides the RandomMixin version. */
404404
void fillrand(std::span<std::byte> output) noexcept;
405405
};
406406

src/script/miniscript.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ struct Node {
593593
* child. It can modify the state. Children of a given node will have downfn()
594594
* called in order.
595595
* - upfn is a callable (State&&, const Node&, std::span<Result>) -> std::optional<Result>,
596-
* which given a node, its state, and a std::span of the results of its children,
596+
* which given a node, its state, and a span of the results of its children,
597597
* computes the result of the node. If std::nullopt is returned by upfn,
598598
* TreeEvalMaybe() immediately returns std::nullopt.
599599
* The return value of TreeEvalMaybe is the result of the root node.

src/span.h

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,49 +11,49 @@
1111
#include <type_traits>
1212
#include <utility>
1313

14-
/** A Span is an object that can refer to a contiguous sequence of objects.
14+
/** A span is an object that can refer to a contiguous sequence of objects.
1515
*
16-
* Things to be aware of when writing code that deals with Spans:
16+
* Things to be aware of when writing code that deals with spans:
1717
*
18-
* - Similar to references themselves, Spans are subject to reference lifetime
18+
* - Similar to references themselves, spans are subject to reference lifetime
1919
* issues. The user is responsible for making sure the objects pointed to by
20-
* a Span live as long as the Span is used. For example:
20+
* a span live as long as the span is used. For example:
2121
*
2222
* std::vector<int> vec{1,2,3,4};
23-
* Span<int> sp(vec);
23+
* std::span<int> sp(vec);
2424
* vec.push_back(5);
2525
* printf("%i\n", sp.front()); // UB!
2626
*
2727
* may exhibit undefined behavior, as increasing the size of a vector may
2828
* invalidate references.
2929
*
30-
* - One particular pitfall is that Spans can be constructed from temporaries,
31-
* but this is unsafe when the Span is stored in a variable, outliving the
30+
* - One particular pitfall is that spans can be constructed from temporaries,
31+
* but this is unsafe when the span is stored in a variable, outliving the
3232
* temporary. For example, this will compile, but exhibits undefined behavior:
3333
*
34-
* Span<const int> sp(std::vector<int>{1, 2, 3});
34+
* std::span<const int> sp(std::vector<int>{1, 2, 3});
3535
* printf("%i\n", sp.front()); // UB!
3636
*
3737
* The lifetime of the vector ends when the statement it is created in ends.
38-
* Thus the Span is left with a dangling reference, and using it is undefined.
38+
* Thus the span is left with a dangling reference, and using it is undefined.
3939
*
40-
* - Due to Span's automatic creation from range-like objects (arrays, and data
40+
* - Due to spans automatic creation from range-like objects (arrays, and data
4141
* types that expose a data() and size() member function), functions that
42-
* accept a Span as input parameter can be called with any compatible
42+
* accept a span as input parameter can be called with any compatible
4343
* range-like object. For example, this works:
4444
*
45-
* void Foo(Span<const int> arg);
45+
* void Foo(std::span<const int> arg);
4646
*
4747
* Foo(std::vector<int>{1, 2, 3}); // Works
4848
*
4949
* This is very useful in cases where a function truly does not care about the
5050
* container, and only about having exactly a range of elements. However it
5151
* may also be surprising to see automatic conversions in this case.
5252
*
53-
* When a function accepts a Span with a mutable element type, it will not
53+
* When a function accepts a span with a mutable element type, it will not
5454
* accept temporaries; only variables or other references. For example:
5555
*
56-
* void FooMut(Span<int> arg);
56+
* void FooMut(std::span<int> arg);
5757
*
5858
* FooMut(std::vector<int>{1, 2, 3}); // Does not compile
5959
* std::vector<int> baz{1, 2, 3};
@@ -69,7 +69,6 @@
6969
* result will be present in that variable after the call. Passing a temporary
7070
* is useless in that context.
7171
*/
72-
#define Span std::span
7372

7473
/** Pop the last element off a span, and return a reference to that element. */
7574
template <typename T>
@@ -81,18 +80,6 @@ T& SpanPopBack(std::span<T>& span)
8180
return back;
8281
}
8382

84-
// From C++20 as_bytes and as_writeable_bytes
85-
template <typename T>
86-
Span<const std::byte> AsBytes(Span<T> s) noexcept
87-
{
88-
return {reinterpret_cast<const std::byte*>(s.data()), s.size_bytes()};
89-
}
90-
template <typename T>
91-
Span<std::byte> AsWritableBytes(Span<T> s) noexcept
92-
{
93-
return {reinterpret_cast<std::byte*>(s.data()), s.size_bytes()};
94-
}
95-
9683
template <typename V>
9784
auto MakeByteSpan(const V& v) noexcept
9885
{
@@ -117,10 +104,10 @@ inline const unsigned char* UCharCast(const std::byte* c) { return reinterpret_c
117104
template <typename B>
118105
concept BasicByte = requires { UCharCast(std::span<B>{}.data()); };
119106

120-
// Helper function to safely convert a Span to a Span<[const] unsigned char>.
107+
// Helper function to safely convert a span to a span<[const] unsigned char>.
121108
template <typename T, size_t N> constexpr auto UCharSpanCast(std::span<T, N> s) { return std::span<std::remove_pointer_t<decltype(UCharCast(s.data()))>, N>{UCharCast(s.data()), s.size()}; }
122109

123-
/** Like the Span constructor, but for (const) unsigned char member types only. Only works for (un)signed char containers. */
110+
/** Like the std::span constructor, but for (const) unsigned char member types only. Only works for (un)signed char containers. */
124111
template <typename V> constexpr auto MakeUCharSpan(const V& v) -> decltype(UCharSpanCast(std::span{v})) { return UCharSpanCast(std::span{v}); }
125112
template <typename V> constexpr auto MakeWritableUCharSpan(V&& v) -> decltype(UCharSpanCast(std::span{std::forward<V>(v)})) { return UCharSpanCast(std::span{std::forward<V>(v)}); }
126113

src/test/span_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ BOOST_AUTO_TEST_SUITE(span_tests)
4444

4545
// Make sure template std::span template deduction guides accurately enable calls to
4646
// std::span constructor overloads that work, and disable calls to constructor overloads that
47-
// don't work. This makes it is possible to use the std::span constructor in a SFINAE
47+
// don't work. This makes it possible to use the std::span constructor in a SFINAE
4848
// contexts like in the Spannable function above to detect whether types are or
49-
// aren't compatible with Spans at compile time.
49+
// aren't compatible with std::span at compile time.
5050
BOOST_AUTO_TEST_CASE(span_constructor_sfinae)
5151
{
5252
BOOST_CHECK(Spannable(std::vector<int>{}));

0 commit comments

Comments
 (0)