[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
This commit is contained in:
Rian Quinn 2016-10-18 12:52:45 -06:00 committed by Neil MacIntosh
parent 1e95421889
commit b07383ead1

View File

@ -93,11 +93,19 @@ inline final_act<F> finally(F&& f) noexcept
} }
// narrow_cast(): a searchable way to do narrowing casts of values // narrow_cast(): a searchable way to do narrowing casts of values
#if _MSC_VER <= 1800
template <class T, class U> template <class T, class U>
inline constexpr T narrow_cast(U u) noexcept inline constexpr T narrow_cast(U u) noexcept
{ {
return static_cast<T>(u); 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 struct narrowing_error : public std::exception
{ {