diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c7dfe0b3..2c1a60f55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -257,7 +257,6 @@ set(libtorrent_aux_include_files throw time torrent_impl - typed_span unique_ptr vector win_crypto_provider diff --git a/include/libtorrent/Makefile.am b/include/libtorrent/Makefile.am index 0901ff635..940143616 100644 --- a/include/libtorrent/Makefile.am +++ b/include/libtorrent/Makefile.am @@ -212,7 +212,6 @@ nobase_include_HEADERS = \ aux_/unique_ptr.hpp \ aux_/alloca.hpp \ aux_/throw.hpp \ - aux_/typed_span.hpp \ aux_/array.hpp \ aux_/ip_notifier.hpp \ aux_/noexcept_movable.hpp \ diff --git a/include/libtorrent/aux_/alloca.hpp b/include/libtorrent/aux_/alloca.hpp index e3dabb8ee..05db406e5 100644 --- a/include/libtorrent/aux_/alloca.hpp +++ b/include/libtorrent/aux_/alloca.hpp @@ -34,7 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_ALLOCA_HPP_INCLUDED #include "libtorrent/config.hpp" -#include "libtorrent/aux_/typed_span.hpp" +#include "libtorrent/span.hpp" #include "libtorrent/aux_/numeric_cast.hpp" #include // for iterator_traits #include // for addressof @@ -77,10 +77,10 @@ struct alloca_destructor #if defined TORRENT_WINDOWS || defined TORRENT_MINGW #include -#define TORRENT_ALLOCA(v, t, n) ::libtorrent::aux::typed_span v; { \ +#define TORRENT_ALLOCA(v, t, n) ::libtorrent::span v; { \ auto TORRENT_ALLOCA_size = ::libtorrent::aux::numeric_cast(n); \ auto* TORRENT_ALLOCA_tmp = static_cast(_alloca(sizeof(t) * static_cast(TORRENT_ALLOCA_size))); \ - v = ::libtorrent::aux::typed_span(TORRENT_ALLOCA_tmp, TORRENT_ALLOCA_size); \ + v = ::libtorrent::span(TORRENT_ALLOCA_tmp, TORRENT_ALLOCA_size); \ ::libtorrent::aux::uninitialized_default_construct(v.begin(), v.end()); \ } \ ::libtorrent::aux::alloca_destructor v##_destructor{v}; @@ -88,10 +88,10 @@ struct alloca_destructor #elif defined TORRENT_BSD #include -#define TORRENT_ALLOCA(v, t, n) ::libtorrent::aux::typed_span v; { \ +#define TORRENT_ALLOCA(v, t, n) ::libtorrent::span v; { \ auto TORRENT_ALLOCA_size = ::libtorrent::aux::numeric_cast(n); \ auto* TORRENT_ALLOCA_tmp = static_cast(alloca(sizeof(t) * static_cast(TORRENT_ALLOCA_size))); \ - v = ::libtorrent::aux::typed_span(TORRENT_ALLOCA_tmp, TORRENT_ALLOCA_size); \ + v = ::libtorrent::span(TORRENT_ALLOCA_tmp, TORRENT_ALLOCA_size); \ ::libtorrent::aux::uninitialized_default_construct(v.begin(), v.end()); \ } \ ::libtorrent::aux::alloca_destructor v##_destructor{v}; @@ -99,10 +99,10 @@ struct alloca_destructor #else #include -#define TORRENT_ALLOCA(v, t, n) ::libtorrent::aux::typed_span v; { \ +#define TORRENT_ALLOCA(v, t, n) ::libtorrent::span v; { \ auto TORRENT_ALLOCA_size = ::libtorrent::aux::numeric_cast(n); \ auto* TORRENT_ALLOCA_tmp = static_cast(alloca(sizeof(t) * static_cast(TORRENT_ALLOCA_size))); \ - v = ::libtorrent::aux::typed_span(TORRENT_ALLOCA_tmp, TORRENT_ALLOCA_size); \ + v = ::libtorrent::span(TORRENT_ALLOCA_tmp, TORRENT_ALLOCA_size); \ ::libtorrent::aux::uninitialized_default_construct(v.begin(), v.end()); \ } \ ::libtorrent::aux::alloca_destructor v##_destructor{v}; diff --git a/include/libtorrent/aux_/storage_utils.hpp b/include/libtorrent/aux_/storage_utils.hpp index d9d4c994a..555aa443e 100644 --- a/include/libtorrent/aux_/storage_utils.hpp +++ b/include/libtorrent/aux_/storage_utils.hpp @@ -39,7 +39,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" #include "libtorrent/fwd.hpp" #include "libtorrent/span.hpp" -#include "libtorrent/aux_/typed_span.hpp" +#include "libtorrent/span.hpp" #include "libtorrent/units.hpp" #include "libtorrent/storage_defs.hpp" // for status_t #include "libtorrent/session_types.hpp" @@ -57,7 +57,7 @@ namespace aux { TORRENT_EXTRA_EXPORT int copy_bufs(span bufs , int bytes, span target); - TORRENT_EXTRA_EXPORT typed_span advance_bufs(typed_span bufs, int bytes); + TORRENT_EXTRA_EXPORT span advance_bufs(span bufs, int bytes); TORRENT_EXTRA_EXPORT void clear_bufs(span bufs); // this is a read or write operation so that readwritev() knows diff --git a/include/libtorrent/aux_/typed_span.hpp b/include/libtorrent/aux_/typed_span.hpp deleted file mode 100644 index 4eadb1c7b..000000000 --- a/include/libtorrent/aux_/typed_span.hpp +++ /dev/null @@ -1,169 +0,0 @@ -/* - -Copyright (c) 2017, Arvid Norberg, Alden Torres -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the distribution. - * Neither the name of the author nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -*/ - -#ifndef TORRENT_TYPED_SPAN_HPP -#define TORRENT_TYPED_SPAN_HPP - -#include - -#include "libtorrent/units.hpp" -#include "libtorrent/span.hpp" -#include "libtorrent/assert.hpp" - -namespace libtorrent { namespace aux { - - template - struct typed_span : span - { - using base = span; - using underlying_index = typename underlying_index_t::type; - using typename span::difference_type; - using typename span::index_type; - - // disallow conversions from other index types - template - typed_span(typed_span const&) = delete; - typed_span() noexcept = default; - typed_span(typed_span const&) noexcept = default; - typed_span& operator=(typed_span const&) noexcept = default; - - template ::value>::type> - typed_span(typed_span const& v) noexcept // NOLINT - : span(v) {} - - typed_span(T& p) noexcept : span(p) {} // NOLINT - typed_span(T* p, difference_type const l) noexcept : span(p, l) {} // NOLINT - - template - typed_span(std::array& arr) noexcept // NOLINT - : span(arr.data(), static_cast(arr.size())) {} - - template - typed_span(U (&arr)[N]) noexcept // NOLINT - : span(&arr[0], N) {} - - // anything with a .data() member function is considered a container - // but only if the value type is compatible with T - template ().data())>::type - , typename = typename std::enable_if::value>::type> - typed_span(Cont& c) : span(c.data(), c.size())// NOLINT - {} - - auto operator[](IndexType idx) const -> -#if TORRENT_AUTO_RETURN_TYPES - decltype(auto) -#else - decltype(this->base::operator[](underlying_index())) -#endif - { - TORRENT_ASSERT(idx >= IndexType(0)); - return this->base::operator[](index_type(static_cast(idx))); - } - - IndexType end_index() const - { - TORRENT_ASSERT(this->size() <= difference_type((std::numeric_limits::max)())); - return IndexType(static_cast(this->size())); - } - - template ::value>::type> - typed_span first(underlying_index n) const - { - TORRENT_ASSERT(n >= 0); - auto const s = this->base::first(difference_type(n)); - return {s.data(), s.size()}; - } - - typed_span first(difference_type n) const - { - TORRENT_ASSERT(n <= difference_type((std::numeric_limits::max)())); - auto const s = this->base::first(n); - return {s.data(), s.size()}; - } - - template ::value>::type> - typed_span last(underlying_index n) const - { - TORRENT_ASSERT(n >= 0); - auto const s = this->base::last(difference_type(n)); - return {s.data(), s.size()}; - } - - typed_span last(difference_type n) const - { - TORRENT_ASSERT(n <= difference_type((std::numeric_limits::max)())); - auto const s = this->base::last(n); - return {s.data(), s.size()}; - } - - template ::value>::type> - typed_span subspan(underlying_index offset) const - { - TORRENT_ASSERT(offset >= 0); - auto const s = this->base::subspan(index_type(offset)); - return {s.data(), s.size()}; - } - - template ::value>::type> - typed_span subspan(underlying_index offset, underlying_index count) const - { - TORRENT_ASSERT(offset >= 0); - TORRENT_ASSERT(count >= 0); - auto const s = this->base::subspan(index_type(offset), difference_type(count)); - return {s.data(), s.size()}; - } - - typed_span subspan(index_type const offset) const - { - TORRENT_ASSERT(offset <= index_type((std::numeric_limits::max)())); - auto const s = this->base::subspan(offset); - return {s.data(), s.size()}; - } - - typed_span subspan(index_type const offset, difference_type const count) const - { - TORRENT_ASSERT(offset <= index_type((std::numeric_limits::max)())); - TORRENT_ASSERT(count <= difference_type((std::numeric_limits::max)())); - auto const s = this->base::subspan(offset, count); - return {s.data(), s.size()}; - } - }; - -}} - -#endif diff --git a/include/libtorrent/piece_picker.hpp b/include/libtorrent/piece_picker.hpp index e25d706d2..36f5fae4a 100644 --- a/include/libtorrent/piece_picker.hpp +++ b/include/libtorrent/piece_picker.hpp @@ -51,7 +51,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/piece_block.hpp" #include "libtorrent/aux_/vector.hpp" #include "libtorrent/aux_/array.hpp" -#include "libtorrent/aux_/typed_span.hpp" +#include "libtorrent/span.hpp" #include "libtorrent/alert_types.hpp" // for picker_flags_t #include "libtorrent/download_priority.hpp" #include "libtorrent/flags.hpp" @@ -465,13 +465,13 @@ namespace libtorrent { // return the array of block_info objects for a given downloading_piece. // this array has m_blocks_per_piece elements in it - aux::typed_span blocks_for_piece(downloading_piece const& dp) const; + span blocks_for_piece(downloading_piece const& dp) const; private: int num_pad_blocks() const { return m_num_pad_blocks; } - aux::typed_span mutable_blocks_for_piece(downloading_piece const& dp); + span mutable_blocks_for_piece(downloading_piece const& dp); std::tuple requested_from( piece_picker::downloading_piece const& p diff --git a/include/libtorrent/sha1_hash.hpp b/include/libtorrent/sha1_hash.hpp index 522f01479..9c6f320bf 100644 --- a/include/libtorrent/sha1_hash.hpp +++ b/include/libtorrent/sha1_hash.hpp @@ -47,7 +47,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/assert.hpp" #include "libtorrent/aux_/byteswap.hpp" #include "libtorrent/aux_/ffs.hpp" -#include "libtorrent/aux_/typed_span.hpp" +#include "libtorrent/span.hpp" #if TORRENT_USE_IOSTREAM #include @@ -58,8 +58,8 @@ namespace libtorrent { // TODO: find a better place for these functions namespace aux { - TORRENT_EXTRA_EXPORT void bits_shift_left(typed_span number, int n); - TORRENT_EXTRA_EXPORT void bits_shift_right(typed_span number, int n); + TORRENT_EXTRA_EXPORT void bits_shift_left(span number, int n); + TORRENT_EXTRA_EXPORT void bits_shift_right(span number, int n); } // This type holds an N digest or any other kind of N bits diff --git a/src/piece_picker.cpp b/src/piece_picker.cpp index 093659f6b..c40ad0a00 100644 --- a/src/piece_picker.cpp +++ b/src/piece_picker.cpp @@ -360,7 +360,7 @@ namespace libtorrent { *zero_prio = int(m_downloads[piece_pos::piece_zero_prio].size()); } - aux::typed_span piece_picker::mutable_blocks_for_piece( + span piece_picker::mutable_blocks_for_piece( downloading_piece const& dp) { int idx = int(dp.info_idx) * m_blocks_per_piece; @@ -368,7 +368,7 @@ namespace libtorrent { return { &m_block_info[idx], blocks_in_piece(dp.index) }; } - aux::typed_span piece_picker::blocks_for_piece( + span piece_picker::blocks_for_piece( downloading_piece const& dp) const { return const_cast(this)->mutable_blocks_for_piece(dp); diff --git a/src/receive_buffer.cpp b/src/receive_buffer.cpp index 12ea48c94..fe7d588ce 100644 --- a/src/receive_buffer.cpp +++ b/src/receive_buffer.cpp @@ -33,7 +33,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/receive_buffer.hpp" #include "libtorrent/invariant_check.hpp" #include "libtorrent/aux_/numeric_cast.hpp" -#include "libtorrent/aux_/typed_span.hpp" +#include "libtorrent/span.hpp" namespace libtorrent { @@ -62,7 +62,7 @@ span receive_buffer::reserve(int const size) m_watermark = {}; } - return aux::typed_span(m_recv_buffer).subspan(m_recv_end, size); + return span(m_recv_buffer).subspan(m_recv_end, size); } void receive_buffer::grow(int const limit) @@ -145,14 +145,14 @@ span receive_buffer::get() const } TORRENT_ASSERT(m_recv_start + m_recv_pos <= int(m_recv_buffer.size())); - return aux::typed_span(m_recv_buffer).subspan(m_recv_start, m_recv_pos); + return span(m_recv_buffer).subspan(m_recv_start, m_recv_pos); } #if !defined TORRENT_DISABLE_ENCRYPTION span receive_buffer::mutable_buffer() { INVARIANT_CHECK; - return aux::typed_span(m_recv_buffer).subspan(m_recv_start, m_recv_pos); + return span(m_recv_buffer).subspan(m_recv_start, m_recv_pos); } span receive_buffer::mutable_buffer(int const bytes) @@ -161,7 +161,7 @@ span receive_buffer::mutable_buffer(int const bytes) // bytes is the number of bytes we just received, and m_recv_pos has // already been adjusted for these bytes. The receive pos immediately // before we received these bytes was (m_recv_pos - bytes) - return aux::typed_span(m_recv_buffer).subspan(m_recv_start + m_recv_pos - bytes, bytes); + return span(m_recv_buffer).subspan(m_recv_start + m_recv_pos - bytes, bytes); } #endif diff --git a/src/sha1_hash.cpp b/src/sha1_hash.cpp index 8c49f2d1b..47e029f20 100644 --- a/src/sha1_hash.cpp +++ b/src/sha1_hash.cpp @@ -62,11 +62,11 @@ namespace libtorrent { namespace aux { - void bits_shift_left(typed_span number, int n) + void bits_shift_left(span const number, int n) { TORRENT_ASSERT(n >= 0); int const num_words = n / 32; - int const number_size = number.end_index(); + int const number_size = int(number.size()); if (num_words >= number_size) { std::memset(number.data(), 0, std::size_t(number.size() * 4)); @@ -100,11 +100,11 @@ namespace aux { } } - void bits_shift_right(typed_span number, int n) + void bits_shift_right(span const number, int n) { TORRENT_ASSERT(n >= 0); int const num_words = n / 32; - int const number_size = number.end_index(); + int const number_size = int(number.size()); if (num_words >= number_size) { std::memset(number.data(), 0, std::size_t(number.size() * 4)); diff --git a/src/storage_utils.cpp b/src/storage_utils.cpp index 9c58373eb..a7bfa469b 100644 --- a/src/storage_utils.cpp +++ b/src/storage_utils.cpp @@ -63,7 +63,7 @@ namespace libtorrent { namespace aux { return ret; } - typed_span advance_bufs(typed_span bufs, int const bytes) + span advance_bufs(span bufs, int const bytes) { TORRENT_ASSERT(bytes >= 0); std::ptrdiff_t size = 0;