RFC: A new helper class

Jarosław Staniek js at iidea.pl
Mon Oct 4 19:37:44 BST 2004

Olivier Goffart wrote:

> Le Lundi 4 Octobre 2004 16:14, Jarosław Staniek a écrit :
>> Allan Sandfeld Jensen wrote:
>> > Maybe I am old-fashioned, but I prefer the traditional C-way of
>> > representing this:
>> > int ret;
>> > ret>0 -> true
>> > ret==0 -> false
>> > ret<0 -> error/exception
>> >
>> > It provides more than one abnormal termination type, which you often
>> > need, and this scheme can also handle any function with positive
>> > integer return-types.
>> Depends whether we want to read documentation or have self-documented
>> code. To montion C-style, there is also other standard behaviour where 0
>> means true.
>> On the other hand, I am (ans we all) also still _using_ ints for wider
>> cases. But there was so many cases for functions using 3-state logic that
>> I've found the class usable.
> Why not a simple enum ?
> In most case, an enum is more redable then a bool if you give meaningfull
> names to the enum members.

As Richard Dale mentioned, booleans are booleans. Unlike simple enum, tristate 
inherits everything from bool type, I mean: operators !, =, and implicity 
casts to (bool).

Operator ~ is consistent addition, in my opinion. Thus even "! ~" working as 
"not cancelled" :)

With tristate class you can forget about it's additional meaning and just 
treat it as a bool.

regards / pozdrawiam,
  Jaroslaw Staniek / OpenOffice Polska
  Kexi Project: http://www.kexi-project.org, http://koffice.kde.org/kexi
  QT-KDE Wrapper Project: http://iidea.pl/~js/qkw

More information about the kde-core-devel mailing list