Sujet : Re: size_t best practice
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.cDate : 18. Aug 2024, 13:17:36
Autres entêtes
Organisation : Stefan Ram
Message-ID : <operator-20240818131412@ram.dialup.fu-berlin.de>
References : 1
Mark Summerfield <
mark@qtrac.eu> wrote or quoted:
So is it considered best practice to use int, long, long long, or size_t,
in situations like these?
In *cough*C++*cough* you could whip up a "SafeSize" class with
a bulletproof "operator--", so you don't space on the check.
You could still keep cranking out your code in what's basically C and
just cherry-pick this one gnarly feature from that other language.
SafeSize& operator--()
{ if( value == 0 )
{ throw std::underflow_error("SafeSize decrement underflow"); }
--value;
return *this; }