From 61534ca3adda0e214d6fb7dd9bc4173edb6e02d1 Mon Sep 17 00:00:00 2001 From: Nicholas Londey Date: Wed, 22 Apr 2020 10:09:13 +1000 Subject: Changed implementation of gsl::narrow to throw gsl::narrowing_error Implementation now behaves as described in the C++ Core Guidlines --- include/gsl/gsl_util | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/gsl/gsl_util b/include/gsl/gsl_util index d1f7f33..bc65923 100644 --- a/include/gsl/gsl_util +++ b/include/gsl/gsl_util @@ -96,6 +96,10 @@ constexpr T narrow_cast(U&& u) noexcept return static_cast(std::forward(u)); } +struct narrowing_error : public std::exception +{ +}; + namespace details { template @@ -115,9 +119,9 @@ constexpr T narrow(U u) noexcept(false) { T t = narrow_cast(u); - if (static_cast(t) != u) gsl::details::terminate(); + if (static_cast(t) != u) throw narrowing_error{}; if (!details::is_same_signedness::value && ((t < T{}) != (u < U{}))) - gsl::details::terminate(); + throw narrowing_error{}; return t; } -- cgit v1.2.3