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