add assignment operator to span
This commit is contained in:
parent
35ad3bb499
commit
a112c8e67b
|
@ -108,6 +108,15 @@ namespace aux {
|
|||
span(Cont const& c) // NOLINT
|
||||
: m_ptr(c.data()), m_len(static_cast<difference_type>(c.size())) {}
|
||||
|
||||
template <typename U, typename
|
||||
= typename std::enable_if<aux::compatible_type<U, T>::value>::type>
|
||||
span& operator=(span<U> 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; }
|
||||
|
|
|
@ -56,6 +56,25 @@ TORRENT_TEST(span_vector)
|
|||
TEST_CHECK(a.size() == 4);
|
||||
}
|
||||
|
||||
TORRENT_TEST(span_vector_assignment)
|
||||
{
|
||||
std::vector<char> v1 = {1,2,3,4};
|
||||
span<char> a;
|
||||
a = v1;
|
||||
TEST_CHECK(a == f(v1));
|
||||
TEST_CHECK(a.size() == 4);
|
||||
}
|
||||
|
||||
TORRENT_TEST(span_assignment)
|
||||
{
|
||||
char v1[] = {1,2,3,4};
|
||||
span<char> a2(v1);
|
||||
span<char> a;
|
||||
a = a2;
|
||||
TEST_CHECK(a == f(v1));
|
||||
TEST_CHECK(a.size() == 4);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
void do_span_temp_vector(span<char const> a)
|
||||
|
|
Loading…
Reference in New Issue