version 3.8
optionalscalar.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_COMMON_OPTIONAL_SCALAR_HH
13#define DUMUX_COMMON_OPTIONAL_SCALAR_HH
14
15#include <limits>
16#include <cmath>
17
18namespace Dumux {
19
25template<class T>
27{
28 static_assert(std::numeric_limits<T>::has_quiet_NaN, "T has to be able to represent a quiet NaN!");
29
30 OptionalScalar() = default;
31
33 : value_(value)
34 {}
35
36 T value() const
37 { return value_; }
38
39 explicit operator bool() const
40 {
41 using std::isnan;
42 return !isnan(value_);
43 }
44private:
45 T value_ = std::numeric_limits<T>::quiet_NaN();
46};
47
48} // namespace Dumux
49
50#endif
Definition: adapt.hh:17
A type for an optional scalar (contains either a valid number or NaN)
Definition: optionalscalar.hh:27
OptionalScalar(T value)
Definition: optionalscalar.hh:32
T value() const
Definition: optionalscalar.hh:36