You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[SUGGESTION] unsafe_narrow is not a good name for forced upcasts. #510
By the way,
I noticed in your other issue (and this one)
that you mixed up the terms upcast and downcast.
Then, I tried to find it in the specification for static_cast,
but it wasn't mentioned, so I just left it unsaid.
Now, I did find other examples.
These use "upcast" when converting from derived to base: https://eel.is/c++draft/class.cdtor#example-3 and https://eel.is/c++draft/class.cdtor#example-1.
Thanks for pointing this out. I knew, that this can also be seen the other way round. I will start using it in terms of the type system and not the functionality.
cpp2::unsafe_narrow is modeled after gsl::narrow_cast. gsl::narrow_castseems to be modeled after gsl::narrow
based on its uses in the C++ Core Guidelines.
Although gsl::narrow_cast<T>(x) is specified as being static_cast<T>(x)
[ Note: static_cast<T>(x) is illegal Cpp2. -- end note ]
it's not clear if those should work with non-arithmetic types:
See isocpp/CppCoreGuidelines#1845 and linked issues (and their linked issues/PRs).
Activity
JohelEGP commentedon Jun 13, 2023
I call this
static_downcast: https://johelegp.github.io/jegp/static.downcast.Inspired by https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-casts-named,
I created my own more specific one.
MaxSagebaum commentedon Jun 13, 2023
Yes, that is also possible.
JohelEGP commentedon Jun 13, 2023
By the way,
I noticed in your other issue (and this one)
that you mixed up the terms upcast and downcast.
Then, I tried to find it in the specification for
static_cast,but it wasn't mentioned, so I just left it unsaid.
Now, I did find other examples.
These use "upcast" when converting from derived to base:
https://eel.is/c++draft/class.cdtor#example-3 and https://eel.is/c++draft/class.cdtor#example-1.
MaxSagebaum commentedon Jun 13, 2023
Thanks for pointing this out. I knew, that this can also be seen the other way round. I will start using it in terms of the type system and not the functionality.
JohelEGP commentedon Jun 19, 2023
cpp2::unsafe_narrowis modeled aftergsl::narrow_cast.gsl::narrow_castseems to be modeled aftergsl::narrowbased on its uses in the C++ Core Guidelines.
Although
gsl::narrow_cast<T>(x)is specified as beingstatic_cast<T>(x)[ Note:
static_cast<T>(x)is illegal Cpp2. -- end note ]it's not clear if those should work with non-arithmetic types:
See isocpp/CppCoreGuidelines#1845 and linked issues (and their linked issues/PRs).
MaxSagebaum commentedon Jun 19, 2023
Ok,
cpp2::unsafe_narrowshould be equally handled as the gsl one. But there should be additional casts in cpp2.