From a112c8e67b74c4044344006947d6d377b277d26f Mon Sep 17 00:00:00 2001 From: arvidn Date: Wed, 12 Dec 2018 09:28:19 +0100 Subject: [PATCH] add assignment operator to span --- include/libtorrent/span.hpp | 9 +++++++++ test/test_span.cpp | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) 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)