Proposal for addition: tristate class - 3-state logical type

Frans Englich frans.englich at telia.com
Sun Sep 11 13:08:29 BST 2005


On Friday 09 September 2005 21:54, Jarosław Staniek wrote:
> File atttached: tristate.h
>
> Proposal for using this at kdelibs level.
>
> Simple yet readable bool type replacement when you need to return a special
> "don't know" or "cancelled" state from your function and you detest
> exceptions like me. I've estarted to use tristate class in apps, including
> Kexi, in 2004 with relative success: I was able to avoid using error-prone
> int type whenever people just want to return 0, 1 or 2 (2=="don't know").
>
> Contains all necessary casts from bool, operators and special 'cancelled'
> value.

If one have an appropriate scenario, I understand if one uses the tristate 
class, considering the convenience and type safety it provides.

Some humble nit-picking:

* The "cancelled" enum in the Value enumerator should also have enum 
capitalization, like True and False. (or there's something I'm missing?)

* Is there any reason to why the variable "value" is not private? Calling it 
m_value could be an idea too. AFAICT, it could be declared const as well.

* Call the class KTristate instead of "tristate"?

* (The Doxygen markup, as per Adriaan)

If concrete cases could be listed for where it would be used(that people will 
adjust code), then I think it would be sensible for it to go in.


FWIW,

		Frans





More information about the kde-core-devel mailing list