make cast operators explicit

This commit is contained in:
Dennis Luxen 2014-09-18 09:42:38 +02:00
parent 41d9c00f70
commit f5e53c0452

View File

@ -40,7 +40,10 @@ namespace osrm
{ {
// implements an binary based fixed point number type // implements an binary based fixed point number type
template <unsigned FractionalBitSize, bool is_unsigned = false, bool truncate_results = false> template <unsigned FractionalBitSize,
bool use_64_bits = false,
bool is_unsigned = false,
bool truncate_results = false>
class FixedPointNumber class FixedPointNumber
{ {
static_assert(FractionalBitSize > 0, "FractionalBitSize must be greater than 0"); static_assert(FractionalBitSize > 0, "FractionalBitSize must be greater than 0");
@ -98,7 +101,7 @@ class FixedPointNumber
// cast to floating point type T, return value // cast to floating point type T, return value
template <typename T, template <typename T,
typename std::enable_if<std::is_floating_point<T>::value>::type * = nullptr> typename std::enable_if<std::is_floating_point<T>::value>::type * = nullptr>
operator T() const noexcept explicit operator T() const noexcept
{ {
// casts to external type (signed or unsigned) and then to float // casts to external type (signed or unsigned) and then to float
return static_cast<T>(static_cast<state_signage>(m_fixed_point_state)) / PRECISION; return static_cast<T>(static_cast<state_signage>(m_fixed_point_state)) / PRECISION;
@ -106,7 +109,7 @@ class FixedPointNumber
// warn about cast to integral type T, its disabled for good reason // warn about cast to integral type T, its disabled for good reason
template <typename T, typename std::enable_if<std::is_integral<T>::value>::type * = nullptr> template <typename T, typename std::enable_if<std::is_integral<T>::value>::type * = nullptr>
operator T() const explicit operator T() const
{ {
static_assert(std::is_integral<T>::value, static_assert(std::is_integral<T>::value,
"casts to integral types have been disabled on purpose"); "casts to integral types have been disabled on purpose");