Skip to content

Commit 397e5ed

Browse files
committed
span: remove default copy ctor and assignment oper
These have the effect of disabling the default move constructor and move operator. This is generally meaningless for spans due to their simplicity, but consider the (simplified here) internal implementation of .first(): Span<C> first(std::size_t count) const noexcept { return Span<C>(m_data, count); } Technically this creates a new Span object and moves/copies it when it returns, but RVO takes care of optimizing that out. Because trivial moves have been implicitly deleted, it falls into the more complicated conversion rvalue constructor to handle the return. The next commit will add an attribute to the conversion constructor to help detect dangling stack references, so we want to make sure that we're not sending trivial copies through it. NOTE: This copy/move is could also be avoided by constructing the return value in-place: Span<C> first(std::size_t count) const noexcept { return {m_data, count}; }
1 parent f32f7e9 commit 397e5ed

File tree

1 file changed

+0
-6
lines changed

1 file changed

+0
-6
lines changed

src/span.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,6 @@ class Span
6161
template <typename O, typename std::enable_if<std::is_convertible<O (*)[], C (*)[]>::value, int>::type = 0>
6262
constexpr Span(const Span<O>& other) noexcept : m_data(other.m_data), m_size(other.m_size) {}
6363

64-
/** Default copy constructor. */
65-
constexpr Span(const Span&) noexcept = default;
66-
67-
/** Default assignment operator. */
68-
Span& operator=(const Span& other) noexcept = default;
69-
7064
/** Construct a Span from an array. This matches the corresponding C++20 std::span constructor. */
7165
template <int N>
7266
constexpr Span(C (&a)[N]) noexcept : m_data(a), m_size(N) {}

0 commit comments

Comments
 (0)