forked from premiere/premiere-libtorrent
add span ctor from const containers (#2275)
This commit is contained in:
parent
d4986f878f
commit
cc3f73de96
|
@ -90,6 +90,15 @@ namespace aux {
|
|||
span(Cont& c) // NOLINT
|
||||
: m_ptr(c.data()), m_len(c.size()) {}
|
||||
|
||||
// allow construction from const containers if T is const
|
||||
// this allows const spans to be constructed from a temporary container
|
||||
template <typename Cont
|
||||
, typename U = typename std::remove_reference<decltype(*std::declval<Cont>().data())>::type
|
||||
, typename = typename std::enable_if<aux::compatible_type<U, T>::value
|
||||
&& std::is_const<T>::value>::type>
|
||||
span(Cont const& c) // NOLINT
|
||||
: m_ptr(c.data()), m_len(c.size()) {}
|
||||
|
||||
std::size_t size() const noexcept { return m_len; }
|
||||
bool empty() const noexcept { return m_len == 0; }
|
||||
T* data() const noexcept { return m_ptr; }
|
||||
|
|
|
@ -52,6 +52,18 @@ TORRENT_TEST(span_vector)
|
|||
TEST_CHECK(a.size() == 4);
|
||||
}
|
||||
|
||||
void do_span_temp_vector(span<char const> a)
|
||||
{
|
||||
std::vector<char> v1 = {1,2,3,4};
|
||||
TEST_CHECK(a == f(v1));
|
||||
TEST_CHECK(a.size() == 4);
|
||||
}
|
||||
|
||||
TORRENT_TEST(span_temp_vector)
|
||||
{
|
||||
do_span_temp_vector(std::vector<char>{1,2,3,4});
|
||||
}
|
||||
|
||||
TORRENT_TEST(span_std_array)
|
||||
{
|
||||
std::array<char, 4> v1{{1,2,3,4}};
|
||||
|
|
Loading…
Reference in New Issue