libzypp  11.13.5
zypp::base::SafeBool< _Derived > Struct Template Reference

Validate objects in a boolean context without harmful side effects. More...

#include <SafeBool.h>

Inheritance diagram for zypp::base::SafeBool< _Derived >:

List of all members.

Public Member Functions

 operator bool_type () const

Protected Member Functions

 ~SafeBool ()

Additional Inherited Members


Detailed Description

template<class _Derived>
struct zypp::base::SafeBool< _Derived >

Validate objects in a boolean context without harmful side effects.

See also:
http://www.artima.com/cppsource/safebool.html

Uses CRTP to avoid a virtual function. _Derived must provide bool boolTest() const preformong the test.

Note:
Using SafeBool enables ==/!= comparision for Foo, based on the bool_type values. Make shure you overload both operators, in case an other semantic is desired for ==/!=.
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
}
};
Todo:
Investigate why Bit refuses private inheritance and exposition of operator bool_type. Seems to be a gcc bug. protected works.

Definition at line 70 of file SafeBool.h.


Constructor & Destructor Documentation

template<class _Derived>
zypp::base::SafeBool< _Derived >::~SafeBool ( )
inlineprotected

Definition at line 80 of file SafeBool.h.


Member Function Documentation

template<class _Derived>
zypp::base::SafeBool< _Derived >::operator bool_type ( ) const
inline

Definition at line 73 of file SafeBool.h.


The documentation for this struct was generated from the following file: