Merge pull request #937 from beinhaerter/cast_warning

eliminate warning, use narrow_cast instead of static_cast
This commit is contained in:
Jordan Maples [MSFT] 2020-10-20 10:55:05 -07:00 committed by GitHub
commit 6432f920ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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, 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, narrow_cast<std::size_t>(lastElem - firstElem))
{} {}
template <std::size_t N, template <std::size_t N,