From bfe6aba728a481229a33fda0e262e5ad2fd8ee41 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Sun, 5 Feb 2017 17:42:19 -0500 Subject: [PATCH] more robust implementation of aux::array::end_index --- include/libtorrent/aux_/array.hpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/libtorrent/aux_/array.hpp b/include/libtorrent/aux_/array.hpp index b44d03e56..6edc18a71 100644 --- a/include/libtorrent/aux_/array.hpp +++ b/include/libtorrent/aux_/array.hpp @@ -46,6 +46,9 @@ namespace libtorrent { namespace aux { using base = std::array; using underlying_index = typename underlying_index_t::type; + static_assert(Size <= std::size_t(std::numeric_limits::max()) + , "size is to big for index type"); + array() = default; explicit array(std::array&& arr) : base(arr) {} @@ -63,10 +66,9 @@ namespace libtorrent { namespace aux { return this->base::operator[](std::size_t(static_cast(idx))); } - IndexType end_index() const + constexpr IndexType end_index() const { - TORRENT_ASSERT(this->size() <= std::size_t(std::numeric_limits::max())); - return IndexType(static_cast(this->size())); + return IndexType(static_cast(Size)); } };