// Default conversion is the standard static cast
template <class SrcType, class DstType>
inline DstType & convert (const SrcType & src, DstType & dst)
{
return dst = static_cast<DstType>(src);
}
// Now define specific conversions:
inline int convert (double src, int & dst)
{
return dst = (src > 0) ? static_cast<int>(src + 0.5) :
static_cast<int>(src - 0.5);
}
inline unsigned int convert (double src, unsigned int & dst)
{
return dst = static_cast<unsigned int>(src + 0.5);
}
// Other conversions omited here to save magazine space