o3tl::make_unsigned

Luboš Luňák l.lunak at collabora.com
Thu Jan 30 14:25:47 UTC 2020


On Thursday 30 of January 2020, Kaganski Mike wrote:
> Can the hypothetical make_signed function return a signed integer when
> there's a bigger integer type exist,

 Yes.

> and a struct with overloaded 
> operator<=> when there's not, and that overloaded operator<=> would
> check if contained unsigned value is greater than max value of its
> signed argument, and return "contained unsigned is greater than passed
> signed" in that case, otherwise fallback to "convert unsigned to signed
> and compare normally" strategy? This would comply with the scope of the
> function (which, as I understand it, to only be used in preparation to
> comparison), always return mathematically correct result of comparison,
> and allow all smaller types comparison to still be without overhead?
> (But for 64-bit unsigned types, of course, it will introduce the
> overhead. Will it be significant, though?)

 Not worth it. That'd be like doing error checking for every memory 
allocation - we also bother only with those few cases where it realistically 
can go wrong.

-- 
 Luboš Luňák
 l.lunak at collabora.com


More information about the LibreOffice mailing list