*/
template<class _IntT>
class BitField : public Range<_IntT, 0, MaxBits<_IntT>::value>
- , public base::SafeBool<BitField<_IntT> >
+ , public base::SafeBool<BitField<_IntT> > /* private, but gcc refuses */
{
+ typedef typename base::SafeBool<BitField<_IntT> >::bool_type bool_type;
+
public:
/** Default ctor: zero. */
BitField()
{}
public:
- /** SafeBool. \see zypp::base::SafeBool */
- bool boolTest() const
- { return _value; }
+ /** Validate in a boolean context. */
+ using base::SafeBool<BitField<_IntT> >::operator bool_type;
public:
/** Return the value. */
{ return ~_value; }
private:
+ friend base::SafeBool<BitField<_IntT> >::operator bool_type() const;
+ /** \ref SafeBool test. */
+ bool boolTest() const
+ { return _value; }
+
+ private:
_IntT _value;
};
///////////////////////////////////////////////////////////////////
* \note Source is a reference to the implementation. No COW
* is performed.
*/
- class Source_Ref : public base::SafeBool<Source_Ref>
+ class Source_Ref : protected base::SafeBool<Source_Ref> /* private, but gcc refuses */
{
friend std::ostream & operator<<( std::ostream & str, const Source_Ref & obj );
friend bool operator==( const Source_Ref & lhs, const Source_Ref & rhs );
*/
static const Source_Ref noSource;
- /** Validate Source_Ref in a boolean context via \ref SafeBool. */
- bool boolTest() const
- { return _pimpl != noSource._pimpl; }
+ /** Validate Source_Ref in a boolean context.
+ * \c FALSE iff == noSource.
+ */
+ using base::SafeBool<Source_Ref>::operator bool_type;
public:
typedef unsigned long NumericId;
media::MediaVerifierRef verifier(unsigned media_nr);
private:
+ friend base::SafeBool<Source_Ref>::operator bool_type() const;
+ /** \ref SafeBool test. */
+ bool boolTest() const
+ { return _pimpl != noSource._pimpl; }
+
+ private:
/** Factory */
friend class SourceFactory;
friend class source::SourceImpl;
inline bool operator==( const Source_Ref & lhs, const Source_Ref & rhs )
{ return lhs._pimpl == rhs._pimpl; }
+ /** \relates Source_Ref */
+ inline bool operator!=( const Source_Ref & lhs, const Source_Ref & rhs )
+ { return ! (lhs == rhs); }
+
/** \relates Source_Ref Order in std::conainer based on _pimpl. */
inline bool operator<( const Source_Ref & lhs, const Source_Ref & rhs )
{ return lhs._pimpl < rhs._pimpl; }
*
* Uses CRTP to avoid a virtual function. \c _Derived must provide
* <tt>bool boolTest() const</tt> preformong the test.
+ *
+ * \note Using SafeBool enables ==/!= comparision for \c Foo, based on
+ * the bool_type values. Make shure you overload \b both operators, in
+ * case an other semantic is desired for ==/!=.
+ *
* \code
- * class Foo : public base::SafeBool<Foo>
+ * class Foo : protected base::SafeBool<Foo>
* {
* public:
+ * using base::SafeBool<Foo>::operator bool_type;
+ *
+ * private:
+ * friend SafeBool<TT>::operator bool_type() const;
* bool boolTest() const
* {
* // Perform Boolean logic here
* };
* \endcode
* \todo Investigate why Bit refuses private inheritance
- * and exposition of operator bool_type.
+ * and exposition of operator bool_type. Seems to be a gcc
+ * bug. protected works.
*/
template<class _Derived>
- struct SafeBool : public safebool_detail::SafeBoolBase
+ struct SafeBool : private safebool_detail::SafeBoolBase
{
+ typedef safebool_detail::SafeBoolBase::bool_type bool_type;
operator bool_type() const
{
return( (static_cast<const _Derived *>(this))->boolTest()