On Thu, Nov 24, 2011 at 10:56:57AM +0100, Lionel Elie Mamane wrote: > I understand we don't want to touch that in stable branch, but anyone > opposing me pushing something like that in master, and similar for > llimit_cast and limit_cast?
> // assumptions: > // \forall typename Type: > // ( (::std::numeric_limits< Type >::min() == 0) XOR ( > ::std::numeric_limits< Type >::min() < 0 && ::std::numeric_limits< Type > >::is_signed )) > // && (::std::numeric_limits< Type >::max() > 0 ) > template< typename ReturnType, typename Type > > inline ReturnType ulimit_cast( Type nValue, ReturnType nMax ) > { > if ( ! ::std::numeric_limits< ReturnType >::is_signed && > ::std::numeric_limits< Type >::is_signed && nValue < 0 ) > return nMax; > // Due to implicit type conversion, the comparison in the if occurs in > the type > // that has the biggest ::max() > // -> safe; compiler gives a warning for mixed signed/unsigned, though > // Assuming unbounded signed types are unbounded towards both infinities. > else if ( ! ::std::numeric_limits< ReturnType >::is_bounded || > ::std::numeric_limits< ReturnType >::max() > > ::std::numeric_limits< Type >::max() ) That should be: else if ( ! ::std::numeric_limits< ReturnType >::is_bounded || nMax > ::std::numeric_limits< Type >::max() ) Obviously. > // nValue fits, and it is unsafe to compare nMax to nValue within Type: > // nMax would be converted > return static_cast < ReturnType >(nValue); > else > // nMax fits in Type; safe to compare to nValue within Type > return static_cast< ReturnType >(::std::min<Type>(nValue, nMax)); > } -- Lionel _______________________________________________ LibreOffice mailing list LibreOffice@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice