diff --git a/mrw/stdext.hpp b/mrw/stdext.hpp
index 242fdda..2a87bc7 100644
--- a/mrw/stdext.hpp
+++ b/mrw/stdext.hpp
@@ -9,6 +9,10 @@
@license LGPL, see file COPYING
$Log$
+ Revision 1.6 2005/02/18 15:47:23 marc
+ missing #ifndef
+ new functions ifelse
+
Revision 1.5 2005/01/28 07:52:33 marc
typo in doc
@@ -27,6 +31,9 @@
*/
+#ifndef __MRW__STDEXT_HPP__
+#define __MRW__STDEXT_HPP__
+
#include
#include
#include
@@ -37,8 +44,14 @@ namespace mrw {
*/
//@{
- /** @defgroup stdextReadline Read Line
+ /** @defgroup stdextFunction Useful Global Functions
+ - @ref getline read exactly one line from a stream
+ - @ref ifelse implements a dual ?:
operator, like:
+ a ? a : b
+
+ @section stdextReadline Read Line
+
The global functions mrw::getline read exactly one line from a
stream, without the need of a buffer. It is therefore guaranteed
that a whole line is read, regardless of the length of the
@@ -94,6 +107,36 @@ namespace mrw {
return std::max(a, b);
}
+ /** @brief Dual ?:
operation:
+ a ? a : b
+
+ If the first parameter is not @c 0, then it is returned,
+ otherwise the second parameter is returned. It is equivalent to
+ the construct: a ? a : b
, but without
+ the side effect of duplicated evaluation of parameter
+ a
.
+
+ Older gcc compiler implemented the non standard extension of
+ a?:b
, which was exactly the same.
+
+ @param a criteria that is checked and returned if not @c 0
+ @param b alternative value to be returned if @c a is @c 0
+ @return a ? a : b
+ @pre #include
+ @pre @c T must be convertible to @c bool
+ */
+ template const T& ifelse(const T& a, const T& b) {
+ return a?a:b;
+ }
+
+ /** @brief Dual ?:
operation:
+ a ? a : b
+
+ @copydoc ifelse(const T& a, const T& b) */
+ template const T* ifelse(const T* a, const T* b) {
+ return a?a:b;
+ }
+
/** @brief read one line from a stream
Reads one line from a stream, up to delimiter @c d.
@@ -123,3 +166,5 @@ namespace mrw {
//@}
//@}
}
+
+#endif