Skip to content

Commit 7beb594

Browse files
committed
Merge branch 'QPR-11075_QL_MSVC_fix' into 'master'
QPR-11075 undo QL changes to Null See merge request qs/quantlib!26
2 parents e55f57d + f99b716 commit 7beb594

4 files changed

Lines changed: 44 additions & 22 deletions

File tree

ql/math/array.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,11 @@ namespace QuantLib {
147147

148148
//! specialization of null template for this class
149149
template <>
150-
inline Array Null<Array>() {
151-
return {};
152-
}
150+
class Null<Array> {
151+
public:
152+
Null() = default;
153+
operator Array() const { return Array(); }
154+
};
153155

154156

155157

ql/prices.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,11 @@ namespace QuantLib {
102102

103103

104104
template <>
105-
inline IntervalPrice Null<IntervalPrice>() {
106-
return {};
105+
class Null<IntervalPrice>
106+
{
107+
public:
108+
Null() = default;
109+
operator IntervalPrice() const { return {}; }
107110
};
108111

109112
}

ql/time/date.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,11 @@ namespace QuantLib {
372372

373373
//! specialization of Null template for the Date class
374374
template <>
375-
inline Date Null<Date>() {
376-
return {};
377-
}
375+
class Null<Date> {
376+
public:
377+
Null() = default;
378+
operator Date() const { return {}; }
379+
};
378380

379381

380382
#ifndef QL_HIGH_RESOLUTION_DATE

ql/utilities/null.hpp

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,25 @@
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

3342
namespace 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

Comments
 (0)