eliminate warning, use narrow_cast instead of static_cast

This commit is contained in:
Werner Henze 2020-10-14 14:53:43 +02:00
parent bd23bdc0ad
commit 2ccf36b4b9

View File

@ -19,6 +19,7 @@
#include <gsl/gsl_assert> // for Expects #include <gsl/gsl_assert> // for Expects
#include <gsl/gsl_byte> // for byte #include <gsl/gsl_byte> // for byte
#include <gsl/gsl_util> // for narrow_cast
#include <array> // for array #include <array> // for array
#include <cstddef> // for ptrdiff_t, size_t, nullptr_t #include <cstddef> // for ptrdiff_t, size_t, nullptr_t
@ -433,14 +434,14 @@ public:
template <std::size_t MyExtent = Extent, std::enable_if_t<MyExtent != dynamic_extent, int> = 0> template <std::size_t MyExtent = Extent, std::enable_if_t<MyExtent != dynamic_extent, int> = 0>
constexpr explicit span(pointer firstElem, pointer lastElem) noexcept constexpr explicit span(pointer firstElem, pointer lastElem) noexcept
: storage_(firstElem, static_cast<std::size_t>(lastElem - firstElem)) : storage_(firstElem, gsl::narrow_cast<std::size_t>(lastElem - firstElem))
{ {
Expects(lastElem - firstElem == static_cast<difference_type>(Extent)); Expects(lastElem - firstElem == static_cast<difference_type>(Extent));
} }
template <std::size_t MyExtent = Extent, std::enable_if_t<MyExtent == dynamic_extent, int> = 0> template <std::size_t MyExtent = Extent, std::enable_if_t<MyExtent == dynamic_extent, int> = 0>
constexpr span(pointer firstElem, pointer lastElem) noexcept constexpr span(pointer firstElem, pointer lastElem) noexcept
: storage_(firstElem, static_cast<std::size_t>(lastElem - firstElem)) : storage_(firstElem, gsl::narrow_cast<std::size_t>(lastElem - firstElem))
{} {}
template <std::size_t N, template <std::size_t N,