Limitations and bugs
#Limitations and bugs
II have a nagging doubt about the implicit conversion to/from value_type
. There are cases where we could have unchecked arithmetic when we expected it to be checked. For example, given:
Style
#Style ThisThis seems old-fashioned:
#Limitations and bugs
I have a nagging doubt about the implicit conversion to/from value_type
. There are cases where we could have unchecked arithmetic when we expected it to be checked. For example, given:
#Style This seems old-fashioned:
Limitations and bugs
I have a nagging doubt about the implicit conversion to/from value_type
. There are cases where we could have unchecked arithmetic when we expected it to be checked. For example, given:
Style
This seems old-fashioned:
All in all, I think the safety would be greatly improved if we declare the conversion to unsafe with the explicit
keyword:
All in all, I think the safety would be greatly improved if we declare the conversion explicit
:
All in all, I think the safety would be greatly improved if we declare the conversion to unsafe with the explicit
keyword:
template<typename T, typename U>
safe_int<std::common_type_t<T,U>> operator+(safe_int<T> a, safe_int<U> b)
{
using V = std::common_type_t<T,U>;
return safe_int<V>(std::move(a)) + safe_int<V>(std::move(b));
}
template<typename T, typename U>
requires Integral<U>std::is_integral_v<U>
safe_int<std::common_type_t<T,U>> operator+(safe_int<T> a, U b)
{
using V = std::common_type_t<T,U>;
return safe_int<V>(std::move(a)) + safe_int<V>(b);
}
template<typename T, typename U>
requires Integral<U>std::is_integral_v<U>
safe_int<std::common_type_t<T,U>> operator+(U a, safe_int<T> b)
{
return std::b + a;
}
template<typename T, typename U>
safe_int<std::common_type_t<T,U>> operator+(safe_int<T> a, safe_int<U> b)
{
using V = std::common_type_t<T,U>;
return safe_int<V>(std::move(a)) + safe_int<V>(std::move(b));
}
template<typename T, typename U>
requires Integral<U>
safe_int<std::common_type_t<T,U>> operator+(safe_int<T> a, U b)
{
using V = std::common_type_t<T,U>;
return safe_int<V>(std::move(a)) + safe_int<V>(b);
}
template<typename T, typename U>
requires Integral<U>
safe_int<std::common_type_t<T,U>> operator+(U a, safe_int<T> b)
{
return b + a;
}
template<typename T, typename U>
safe_int<std::common_type_t<T,U>> operator+(safe_int<T> a, safe_int<U> b)
{
using V = std::common_type_t<T,U>;
return safe_int<V>(std::move(a)) + safe_int<V>(std::move(b));
}
template<typename T, typename U>
requires std::is_integral_v<U>
safe_int<std::common_type_t<T,U>> operator+(safe_int<T> a, U b)
{
using V = std::common_type_t<T,U>;
return safe_int<V>(std::move(a)) + safe_int<V>(b);
}
template<typename T, typename U>
requires std::is_integral_v<U>
safe_int<std::common_type_t<T,U>> operator+(U a, safe_int<T> b)
{
return std::b + a;
}
- 87.3k
- 14
- 104
- 322