missing #ifndef

new functions ifelse
master
Marc Wäckerlin 20 years ago
parent fd5ec4b79c
commit 0ff3cecc1c
  1. 47
      mrw/stdext.hpp

@ -9,6 +9,10 @@
@license LGPL, see file <a href="license.html">COPYING</a>
$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 <string>
#include <iostream>
#include <algorithm>
@ -37,7 +44,13 @@ 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 <code>?:</code> operator, like:
<code>a&nbsp;?&nbsp;a&nbsp;:&nbsp;b</code>
@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
@ -94,6 +107,36 @@ namespace mrw {
return std::max(a, b);
}
/** @brief Dual <code>?:</code> operation:
<code>a&nbsp;?&nbsp;a&nbsp;:&nbsp;b</code>
If the first parameter is not @c 0, then it is returned,
otherwise the second parameter is returned. It is equivalent to
the construct: <code>a&nbsp;?&nbsp;a&nbsp;:&nbsp;b</code>, but without
the side effect of duplicated evaluation of parameter
<code>a</code>.
Older gcc compiler implemented the non standard extension of
<code>a?:b</code>, 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 <code>a&nbsp;?&nbsp;a&nbsp;:&nbsp;b</code>
@pre #include <mrw/stdext.hpp>
@pre @c T must be convertible to @c bool
*/
template<typename T> const T& ifelse(const T& a, const T& b) {
return a?a:b;
}
/** @brief Dual <code>?:</code> operation:
<code>a&nbsp;?&nbsp;a&nbsp;:&nbsp;b</code>
@copydoc ifelse(const T& a, const T& b) */
template<typename T> 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

Loading…
Cancel
Save