CppCoreGuidelines
CppCoreGuidelines copied to clipboard
Should gsl::narrow include slicing
Re: Microsoft/GSL#917 Should narrow and narrow_cast also apply to slicing, because slicing also allows for going from larger to smaller ranges of value. Both could be considered lossy.
Thanks.
Also see: https://github.com/microsoft/GSL/pull/900
The C++ Core Guidelines simply specify
gsl::narrow
asnarrow // narrow<T>(x) is static_cast<T>(x) if static_cast<T>(x) == x or it throws narrowing_error
. The implementation uses relational operators, so I can't dogsl::narrow<point<unsigned>>(point<int>{})
for mypoint
type.