2727#define quantlib_null_hpp
2828
2929#include < ql/types.hpp>
30- #include < type_traits>
31- #include < limits>
30+
31+ #if defined(__GNUC__) && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)) || (__GNUC__ > 4))
32+ #pragma GCC diagnostic push
33+ #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
34+ #endif
35+
36+ #include < boost/type_traits.hpp>
37+
38+ #if defined(__GNUC__) && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)) || (__GNUC__ > 4))
39+ #pragma GCC diagnostic pop
40+ #endif
3241
3342namespace QuantLib {
3443
35-
36-
44+ // ! template class providing a null value for a given type.
45+ template <class Type >
46+ class Null ;
47+
48+
3749 namespace detail {
3850
3951 template <bool >
@@ -42,28 +54,31 @@ namespace QuantLib {
4254 // null value for floating-point types
4355 template <>
4456 struct FloatingPointNull <true > {
45- constexpr static float nullValue () {
46- // a specific values that should fit into any Real
47- return (std::numeric_limits<float >::max)();
57+ static float nullValue () {
58+ return QL_NULL_REAL;
4859 }
4960 };
5061
5162 // null value for integer types
5263 template <>
5364 struct FloatingPointNull <false > {
54- constexpr static int nullValue () {
55- // a specific values that should fit into any Integer
56- return (std::numeric_limits<int >::max)();
65+ static int nullValue () {
66+ return QL_NULL_INTEGER;
5767 }
5868 };
5969
6070 }
6171
62- // ! template function providing a null value for a given type.
72+ // default implementation for built-in types
6373 template <typename T>
64- T Null () {
65- return T (detail::FloatingPointNull<std::is_floating_point<T>::value>::nullValue ());
66- }
74+ class Null {
75+ public:
76+ Null () = default ;
77+ operator T () const {
78+ return T (detail::FloatingPointNull<
79+ boost::is_floating_point<T>::value>::nullValue ());
80+ }
81+ };
6782
6883}
6984
0 commit comments