mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
[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:
parent
1e95421889
commit
b07383ead1
@ -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
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user