
From: "Steven Watanabe" <watanabesj@gmail.com> So, here's another take on it:
template<class Tag> struct safe_bool { typedef void (safe_bool::*result_type)(); result_type operator()(bool b) { return b? &safe_bool::true_ : 0 } private: void true_() {} };
Yes, "templatazing" makes sense. The deployment will probably be as follows: class Foo { ... operator safe_bool<Foo>::result_type() const { return safe_bool<Foo>()(my_condition); } }; Is it considerably different from what I suggested initially? That is, class Foo { ... operator safebool<Foo>::result() const { return safebool<Foo>(my_condition); } }; I do understand that my suggested variant stores the condition internally. I did it for the sake of simplifying the user interface as I find the usage immediately above fairly conventional. Does that variable adds too much overhead? A way to avoid it certainly would be via a function similar to: operator safebool<Foo>::result() const { return safebool<Foo>::apply(my_condition); } operator safebool<Foo>::result() const { return safebool<Foo>()(my_condition); } Best, V.