doc
This commit is contained in:
parent
122b7442c1
commit
3f817db6d4
1 changed files with 44 additions and 2 deletions
|
|
@ -24,11 +24,48 @@ Lionel Parreaux <lionel.parreaux@gmail.com>
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** @defgroup Logging Logging
|
/**
|
||||||
* @ingroup Utilities
|
|
||||||
|
A utility class for wrapping non-const references and use them as default arguments in functions.
|
||||||
|
|
||||||
|
For example, this is not valid C++98 code:
|
||||||
|
|
||||||
|
\code
|
||||||
|
struct MyClass {
|
||||||
|
MyClass(T& my_T = default_T)
|
||||||
|
: actual_T(my_T)
|
||||||
|
{ }
|
||||||
|
private:
|
||||||
|
T default_T;
|
||||||
|
T& actual_T;
|
||||||
|
}
|
||||||
|
\endcode
|
||||||
|
|
||||||
|
This is the same code using eoOptional, which is valid:
|
||||||
|
|
||||||
|
\code
|
||||||
|
struct MyClass {
|
||||||
|
MyClass(eoOptional<T> my_T = NULL)
|
||||||
|
: actual_T(my_T.getOr(default_T))
|
||||||
|
{ }
|
||||||
|
private:
|
||||||
|
T default_T;
|
||||||
|
T& actual_T;
|
||||||
|
}
|
||||||
|
\endcode
|
||||||
|
|
||||||
|
And from the point of view of the user, it is transparent:
|
||||||
|
|
||||||
|
\code
|
||||||
|
// Three ways of using MyClass:
|
||||||
|
MyClass mc1;
|
||||||
|
MyClass mc2(NULL);
|
||||||
|
T t;
|
||||||
|
MyClass mc3(t);
|
||||||
|
\endcode
|
||||||
|
|
||||||
|
|
||||||
|
@ingroup Utilities
|
||||||
@{
|
@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -47,6 +84,11 @@ public:
|
||||||
: _val(&init)
|
: _val(&init)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
// used mainly for converting NULL to this
|
||||||
|
eoOptional (T* init)
|
||||||
|
: _val(init)
|
||||||
|
{ }
|
||||||
|
|
||||||
bool hasValue() const
|
bool hasValue() const
|
||||||
{
|
{
|
||||||
return _val != NULL;
|
return _val != NULL;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue