3
* Copyright (C) 2006 Remko Troncon
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
* \brief A template class either containing no value or a specific value.
26
* This container is especially handy for types that do not have an isNull()
27
* or isEmpty() (such as primitive types).
29
* Example: Returns the division of numer and denom if it is an integer
31
* Maybe<int> integer_divide(int numer, int denom) {
32
* if (numer % denom == 0)
33
* return Maybe<int>(numer / denom);
35
* return Maybe<int>();
39
template<class T> class Maybe
43
* \brief Constructs a Maybe container with no value.
45
Maybe() : hasValue_(false) {}
48
* \brief Constructs a Maybe container with a value.
50
Maybe(const T& value) : value_(value), hasValue_(true) {}
53
* \brief Checks whether this container has a value.
55
bool hasValue() const { return hasValue_; }
58
* \brief Returns the value of the container.
60
const T& value() const { return value_; }