diff options
author | Nicholas Londey <nicholas@londey.com> | 2020-04-22 03:09:13 +0300 |
---|---|---|
committer | Nicholas Londey <nicholas@londey.com> | 2020-04-22 03:09:13 +0300 |
commit | 61534ca3adda0e214d6fb7dd9bc4173edb6e02d1 (patch) | |
tree | bdf6fc23ae35f6fc2fb5f66e923080de3d83753e /include | |
parent | 9f6a9a5807ad0de9c9c5294ece20639a5538f485 (diff) |
Changed implementation of gsl::narrow to throw gsl::narrowing_error
Implementation now behaves as described in the C++ Core Guidlines
Diffstat (limited to 'include')
-rw-r--r-- | include/gsl/gsl_util | 8 |
1 files changed, 6 insertions, 2 deletions
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<T>(std::forward<U>(u)); } +struct narrowing_error : public std::exception +{ +}; + namespace details { template <class T, class U> @@ -115,9 +119,9 @@ constexpr T narrow(U u) noexcept(false) { T t = narrow_cast<T>(u); - if (static_cast<U>(t) != u) gsl::details::terminate(); + if (static_cast<U>(t) != u) throw narrowing_error{}; if (!details::is_same_signedness<T, U>::value && ((t < T{}) != (u < U{}))) - gsl::details::terminate(); + throw narrowing_error{}; return t; } |