diff --git a/include/libtorrent/span.hpp b/include/libtorrent/span.hpp index 1ff8776df..72dbbd03d 100644 --- a/include/libtorrent/span.hpp +++ b/include/libtorrent/span.hpp @@ -108,6 +108,15 @@ namespace aux { span(Cont const& c) // NOLINT : m_ptr(c.data()), m_len(static_cast(c.size())) {} + template ::value>::type> + span& operator=(span const& rhs) noexcept + { + m_ptr = rhs.data(); + m_len = rhs.size(); + return *this; + } + index_type size() const noexcept { return m_len; } bool empty() const noexcept { return m_len == 0; } T* data() const noexcept { return m_ptr; } diff --git a/test/test_span.cpp b/test/test_span.cpp index 1f4add6ea..a7a0420f9 100644 --- a/test/test_span.cpp +++ b/test/test_span.cpp @@ -56,6 +56,25 @@ TORRENT_TEST(span_vector) TEST_CHECK(a.size() == 4); } +TORRENT_TEST(span_vector_assignment) +{ + std::vector v1 = {1,2,3,4}; + span a; + a = v1; + TEST_CHECK(a == f(v1)); + TEST_CHECK(a.size() == 4); +} + +TORRENT_TEST(span_assignment) +{ + char v1[] = {1,2,3,4}; + span a2(v1); + span a; + a = a2; + TEST_CHECK(a == f(v1)); + TEST_CHECK(a.size() == 4); +} + namespace { void do_span_temp_vector(span a)