Added utility method getOr(T&) in eoOptional

This commit is contained in:
LPTK 2013-06-12 15:44:59 +02:00
commit 290ff1cfd1

View file

@ -38,7 +38,7 @@ struct MyClass {
private: private:
T default_T; T default_T;
T& actual_T; T& actual_T;
} };
\endcode \endcode
This is the same code using eoOptional, which is valid: This is the same code using eoOptional, which is valid:
@ -51,7 +51,7 @@ struct MyClass {
private: private:
T default_T; T default_T;
T& actual_T; T& actual_T;
} };
\endcode \endcode
And from the point of view of the user, it is transparent: And from the point of view of the user, it is transparent:
@ -84,7 +84,7 @@ public:
: _val(&init) : _val(&init)
{ } { }
// used mainly for converting NULL to this // used mainly for converting NULL to this class
eoOptional (T* init) eoOptional (T* init)
: _val(init) : _val(init)
{ } { }
@ -101,6 +101,11 @@ public:
return *_val; return *_val;
} }
T& getOr (T& default) const
{
return hasValue()? *_val: default;
}
protected: protected:
eoOptional () eoOptional ()
: _val(NULL) : _val(NULL)