CppCoreGuidelines
CppCoreGuidelines copied to clipboard
Is gsl::narrow intended to work with custom arithmetic types?
An issue ( Microsoft/gsl#990 ) was recently filed in the Microsoft GSL repository, requesting additional support for gsl::narrow on custom arithmetic types. Do the CppCoreGuidelines intend for narrow to support custom arithmetic types.
Also should enums be considered for this narrow support as well? Should narrow be allow to cast from a scoped enum to a different type than its underlying type directly?
Link to the users proof of concept: https://github.com/microsoft/GSL/issues/990#issuecomment-891246530
This was also brought up in #1726 but not quite answered there
Editors call: The default answer is that it should work with custom arithmetic types, if there is no difference in performance. If making it work with custom arithmetic types has a performance difference when used with built-in arithmetic types, then we will have to reconsider.
Is there necessarily a difference in performance for the built-in arithmetic types?