On 28 Jun 2015 at 9:30, Robert Ramey wrote:
On 6/28/15 6:15 AM, Niall Douglas wrote:
https://github.com/ned14/boost.spinlock/blob/master/include/boost/spin lock/tribool.hpp
How is this better/different than the current boost::tribool?
1. Mine is 100% constexpr. 2. I think mine implements std::min/max and other ternary logic primitives Boost.Tribool does not. I didn't look into it in detail. 3. Mine is much more conservatively designed. Specifically: a. No automatic conversion operators, thus preventing assert(something==!!something). It also forces the programmer to explicitly state what they mean when working with tribools, see below. b. operator&& and operator|| return bool, not tribool. If you want tribool outcomes, use the bitwise operators. I'm also matching 100% the C++ standard text on this where logical operators are supposed to return only bool.
I've used this on several occasions with good success. It's well documented as well.
I was being incredibly paranoid with my tribool. Almost certainly excessively so. But they're new to me, so I was being extra cautious to make sure I didn't shoot myself in the foot later. Besides, writing this by hand: tribool t; if(true_(t)) ... else if(false_(t)) ... else if(unknown_(t)) ... ... isn't too bad, and has the advantage of being very clear even to programmers not familiar with tribool (i.e. me). Niall -- ned Productions Limited Consulting http://www.nedproductions.biz/ http://ie.linkedin.com/in/nialldouglas/