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
Naming is difficult. From my point of view, cast is cryptic name as well because it is not immediately obvious whether the function performs range checking before casting, which could lead to unexpected behavior. It might be that something like checked_cast will be better.
The cast from wrapper type to the native type is a little bit misleading because wrapper type already knows very well the native type. So, it might be better to implement something like this:
template <typename T>
T cast(Number<T> value)
{
return value.value();
}
This allows to write something like
int w = cast<int>(v);
or
int w = cast(v);
but not something like
int w = cast<unsigned>(v);
If cast without <int> looks strange, we can disable it. But then, users will have to specify something which might be redundant.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Instead of using the cryptic names why do we not just make several template functions, called 'zserio::cast' ?
Example on how the API could look like (no actual numerical range checking is implemented):
Beta Was this translation helpful? Give feedback.
All reactions