From 3f817db6d47b6ef4f836100bc334810f1baf03dd Mon Sep 17 00:00:00 2001 From: LPTK Date: Wed, 12 Jun 2013 15:38:40 +0200 Subject: [PATCH] doc --- eo/src/eoOptional.h | 48 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/eo/src/eoOptional.h b/eo/src/eoOptional.h index d3cdbff80..905da51d4 100644 --- a/eo/src/eoOptional.h +++ b/eo/src/eoOptional.h @@ -24,11 +24,48 @@ Lionel Parreaux */ -/** @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 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 @{ */ @@ -46,6 +83,11 @@ public: eoOptional (T& init) : _val(&init) { } + + // used mainly for converting NULL to this + eoOptional (T* init) + : _val(init) + { } bool hasValue() const {