From b07383ead13d46ead9090fcd80dbd79ae6154bac Mon Sep 17 00:00:00 2001 From: Rian Quinn Date: Tue, 18 Oct 2016 12:52:45 -0600 Subject: [PATCH] [gsl_util] Update narrow_cast to use std::forward * Update narrow_cast to use std::forward Based on [F19](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#f19-for-forward-parameters-pass-by-tp-and-only-stdforward-the-parameter), I believe `gsl::narrow_cast` should be implemented using forward semantics. * Fix for VS 2013 --- gsl/gsl_util | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gsl/gsl_util b/gsl/gsl_util index 17a1edb..f0ac964 100644 --- a/gsl/gsl_util +++ b/gsl/gsl_util @@ -93,11 +93,19 @@ inline final_act finally(F&& f) noexcept } // narrow_cast(): a searchable way to do narrowing casts of values +#if _MSC_VER <= 1800 template inline constexpr T narrow_cast(U u) noexcept { return static_cast(u); } +#else +template +inline constexpr T narrow_cast(U&& u) noexcept +{ + return static_cast(std::forward(u)); +} +#endif struct narrowing_error : public std::exception {