aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRian Quinn <rianquinn@gmail.com>2016-10-18 12:52:45 -0600
committerNeil MacIntosh <neilmac@microsoft.com>2016-10-18 11:52:45 -0700
commitb07383ead13d46ead9090fcd80dbd79ae6154bac (patch)
treeba0aeb9d81cfe42f753789755a6e47395645ea07
parent1e95421889b3f14224cd02984bf713375092f06d (diff)
downloadplatform_external_Microsoft-GSL-b07383ead13d46ead9090fcd80dbd79ae6154bac.tar.gz
platform_external_Microsoft-GSL-b07383ead13d46ead9090fcd80dbd79ae6154bac.tar.bz2
platform_external_Microsoft-GSL-b07383ead13d46ead9090fcd80dbd79ae6154bac.zip
[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
-rw-r--r--gsl/gsl_util8
1 files changed, 8 insertions, 0 deletions
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<F> finally(F&& f) noexcept
}
// narrow_cast(): a searchable way to do narrowing casts of values
+#if _MSC_VER <= 1800
template <class T, class U>
inline constexpr T narrow_cast(U u) noexcept
{
return static_cast<T>(u);
}
+#else
+template <class T, class U>
+inline constexpr T narrow_cast(U&& u) noexcept
+{
+ return static_cast<T>(std::forward<U>(u));
+}
+#endif
struct narrowing_error : public std::exception
{