QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
null.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
5 Copyright (C) 2003, 2004 StatPro Italia srl
6 Copyright (C) 2010 Kakhkhor Abdijalilov
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
22/*! \file null.hpp
23 \brief null values
24*/
25
26#ifndef quantlib_null_hpp
27#define quantlib_null_hpp
28
29#include <ql/types.hpp>
30#include <type_traits>
31#include <limits>
32
33namespace QuantLib {
34
35 namespace detail {
36
37 template <bool>
39
40 // null value for floating-point types
41 template <>
42 struct FloatingPointNull<true> {
43 constexpr static float nullValue() {
44 // a specific values that should fit into any Real
45 return (std::numeric_limits<float>::max)();
46 }
47 };
48
49 // null value for integer types
50 template <>
51 struct FloatingPointNull<false> {
52 constexpr static int nullValue() {
53 // a specific values that should fit into any Integer
54 return (std::numeric_limits<int>::max)();
55 }
56 };
57
58 }
59
60 #ifdef QL_NULL_AS_FUNCTIONS
61
62 //! template function providing a null value for a given type.
63 template <typename T>
64 T Null() {
65 return T(detail::FloatingPointNull<std::is_floating_point<T>::value>::nullValue());
66 }
67
68 #else
69
70 //! template class providing a null value for a given type.
71 template <class Type>
72 class Null;
73
74 // default implementation for built-in types
75 template <typename T>
76 class Null {
77 public:
78 Null() = default;
79 operator T() const {
80 return T(detail::FloatingPointNull<std::is_floating_point<T>::value>::nullValue());
81 }
82 };
83
84 #endif
85
86}
87
88
89#endif
template class providing a null value for a given type.
Definition: null.hpp:76
Null()=default
Definition: any.hpp:35
static constexpr int nullValue()
Definition: null.hpp:52
static constexpr float nullValue()
Definition: null.hpp:43
Custom types.