CppCoreGuidelines icon indicating copy to clipboard operation
CppCoreGuidelines copied to clipboard

Is gsl::narrow intended to work with custom arithmetic types?

Open JordanMaples opened this issue 4 years ago • 2 comments

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

JordanMaples avatar Aug 04 '21 22:08 JordanMaples

This was also brought up in #1726 but not quite answered there

cubbimew avatar Aug 05 '21 03:08 cubbimew

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?

hsutter avatar Aug 19 '21 18:08 hsutter