Skip to content

Commit

Permalink
Merge 0033063 into 63bac2f
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Aug 27, 2022
2 parents 63bac2f + 0033063 commit 1f9b454
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 8 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/linux-full-tests.yml
Expand Up @@ -97,7 +97,7 @@ jobs:
tag: rolling
cc: gcc
cxx: g++
cxxflags: "-std=c++11"
cxxflags: "-std=c++11 -Wno-cpp"
- name: "C++14 mode"
shortname: c++14
tag: rolling
Expand Down Expand Up @@ -164,6 +164,12 @@ jobs:
cc: gcc
cxx: g++
configureflags: --enable-openmp
- name: "Null as function template"
shortname: nullfunctions
tag: rolling
cc: gcc
cxx: g++
configureflags: --enable-null-as-functions
container: ghcr.io/lballabio/quantlib-devenv:${{ matrix.tag }}
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux-nondefault.yml
Expand Up @@ -149,7 +149,7 @@ jobs:
- name: Build
run: |
./autogen.sh
./configure --disable-static --enable-error-lines --enable-error-functions --enable-tracing --enable-indexed-coupons --enable-extra-safety-checks --enable-sessions --enable-thread-safe-observer-pattern --enable-intraday ${{ matrix.configureflags }} CC="ccache ${{ matrix.cc }}" CXX="ccache ${{ matrix.cxx }}" CXXFLAGS="-O2 -g0 -Wall -Wno-unknown-pragmas -Werror ${{ matrix.cxxflags }}"
./configure --disable-static --enable-error-lines --enable-error-functions --enable-tracing --enable-indexed-coupons --enable-extra-safety-checks --enable-sessions --enable-thread-safe-observer-pattern --enable-intraday --enable-null-as-functions ${{ matrix.configureflags }} CC="ccache ${{ matrix.cc }}" CXX="ccache ${{ matrix.cxx }}" CXXFLAGS="-O2 -g0 -Wall -Wno-unknown-pragmas -Werror ${{ matrix.cxxflags }}"
make -j 2
- name: Run tests
run: |
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/linux.yml
Expand Up @@ -99,7 +99,7 @@ jobs:
tag: rolling
cc: gcc
cxx: g++
cxxflags: "-std=c++11"
cxxflags: "-std=c++11 -Wno-cpp"
- name: "C++14 mode"
shortname: c++14
tag: rolling
Expand Down Expand Up @@ -180,6 +180,13 @@ jobs:
cxx: g++
configureflags: --enable-parallel-unit-test-runner
moreflags: -lrt
- name: "Null as function template"
shortname: nullfunctions
tag: rolling
cc: gcc
cxx: g++
configureflags: --enable-null-as-functions
tests: true
container: ghcr.io/lballabio/quantlib-devenv:${{ matrix.tag }}
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos-nondefault.yml
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Build
run: |
./autogen.sh
./configure --disable-shared --enable-error-lines --enable-error-functions --enable-tracing --enable-indexed-coupons --enable-extra-safety-checks --enable-sessions --enable-thread-safe-observer-pattern --enable-intraday ${{ matrix.configureflags }} CC="ccache clang" CXX="ccache clang++" CXXFLAGS="-O2 -g0 -Wall -Werror -stdlib=libc++ -mmacosx-version-min=10.9 ${{ matrix.cxxflags }}" LDFLAGS="-stdlib=libc++ -mmacosx-version-min=10.9"
./configure --disable-shared --enable-error-lines --enable-error-functions --enable-tracing --enable-indexed-coupons --enable-extra-safety-checks --enable-sessions --enable-thread-safe-observer-pattern --enable-intraday --enable-null-as-functions ${{ matrix.configureflags }} CC="ccache clang" CXX="ccache clang++" CXXFLAGS="-O2 -g0 -Wall -Werror -stdlib=libc++ -mmacosx-version-min=10.9 ${{ matrix.cxxflags }}" LDFLAGS="-stdlib=libc++ -mmacosx-version-min=10.9"
make -j 2
- name: Run tests
run: |
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -52,6 +52,7 @@ option(QL_ERROR_FUNCTIONS "Error messages should include current function inform
option(QL_ERROR_LINES "Error messages should include file and line information" OFF)
option(QL_EXTRA_SAFETY_CHECKS "Extra safety checks should be performed" OFF)
option(QL_HIGH_RESOLUTION_DATE "Enable date resolution down to microseconds" OFF)
option(QL_NULL_AS_FUNCTIONS "Enable the implementation of Null as template functions" OFF)
option(QL_INSTALL_BENCHMARK "Install benchmark" ON)
option(QL_INSTALL_EXAMPLES "Install examples" ON)
option(QL_INSTALL_TEST_SUITE "Install test suite" ON)
Expand Down
2 changes: 2 additions & 0 deletions CMakePresets.json
Expand Up @@ -109,6 +109,7 @@
"QL_ENABLE_SESSIONS": "ON",
"QL_ENABLE_THREAD_SAFE_OBSERVER_PATTERN": "ON",
"QL_HIGH_RESOLUTION_DATE": "ON",
"QL_NULL_AS_FUNCTIONS": "ON",
"QL_USE_INDEXED_COUPON": "ON",
"QL_USE_STD_CLASSES": "ON"
}
Expand All @@ -126,6 +127,7 @@
"QL_ENABLE_SESSIONS": "ON",
"QL_ENABLE_THREAD_SAFE_OBSERVER_PATTERN": "ON",
"QL_HIGH_RESOLUTION_DATE": "ON",
"QL_NULL_AS_FUNCTIONS": "ON",
"QL_USE_INDEXED_COUPON": "ON",
"QL_USE_STD_CLASSES": "ON"
},
Expand Down
9 changes: 9 additions & 0 deletions Docs/pages/config.docs
Expand Up @@ -127,6 +127,15 @@
are used instead of `boost::tuple`. If disabled (the
default) the Boost facilities are used.

\code
#define QL_NULL_AS_FUNCTIONS
\endcode
If defined, `Null` will be implemented as a set of template
functions. This allows the code to work with user-defined `Real`
types but was reported to cause internal compiler errors with
Visual C++ 2022 in some cases. If disabled (the default) `Null`
will be implemented as a class template, as in previous releases.

\code
#define QL_ENABLE_PARALLEL_UNIT_TEST_RUNNER
\endcode
Expand Down
20 changes: 19 additions & 1 deletion configure.ac
Expand Up @@ -391,7 +391,6 @@ if test "$ql_use_std_function" = "yes" ; then
fi
AC_MSG_RESULT([$ql_use_std_function])


AC_MSG_CHECKING([whether to enable std::tuple])
AC_ARG_ENABLE([std-tuple],
AS_HELP_STRING([--enable-std-tuple],
Expand Down Expand Up @@ -426,6 +425,25 @@ if test "$ql_use_std_classes" = "yes" ; then
fi
AC_MSG_RESULT([$ql_use_std_classes])

AC_MSG_CHECKING([whether to enable the implementation of Null as template functions])
AC_ARG_ENABLE([null-as-functions],
AS_HELP_STRING([--enable-null-as-functions],
[If enabled, Null will be implemented as a set
of template functions. This allows the code
to work with user-defined Real types but was
reported to cause internal compiler errors
with Visual C++ 2022 in some cases.
If disabled (the default) Null will be
implemented as a class template, as in
previous releases.]),
[ql_use_null_functions=$enableval],
[ql_use_null_functions=no])
if test "$ql_use_null_functions" = "yes" ; then
AC_DEFINE([QL_NULL_AS_FUNCTIONS],[1],
[Define this if you want to enable the implementation of Null as template functions.])
fi
AC_MSG_RESULT([$ql_use_null_functions])


# manual configurations for specific hosts
case $host in
Expand Down
1 change: 1 addition & 0 deletions ql/config.hpp.cfg
Expand Up @@ -40,5 +40,6 @@
#cmakedefine QL_USE_STD_SHARED_PTR
#cmakedefine QL_USE_STD_FUNCTION
#cmakedefine QL_USE_STD_TUPLE
#cmakedefine QL_NULL_AS_FUNCTIONS

#endif
12 changes: 12 additions & 0 deletions ql/math/array.hpp
Expand Up @@ -145,13 +145,25 @@ namespace QuantLib {
Size n_;
};

#ifdef QL_NULL_AS_FUNCTIONS

//! specialization of null template for this class
template <>
inline Array Null<Array>() {
return {};
}

#else

//! specialization of null template for this class
template <>
class Null<Array> {
public:
Null() = default;
operator Array() const { return Array(); }
};

#endif

/*! \relates Array */
Real DotProduct(const Array&, const Array&);
Expand Down
15 changes: 14 additions & 1 deletion ql/prices.hpp
Expand Up @@ -100,12 +100,25 @@ namespace QuantLib {
Real open_, close_, high_, low_;
};


#ifdef QL_NULL_AS_FUNCTIONS

template <>
inline IntervalPrice Null<IntervalPrice>() {
return {};
};

#else

template <>
class Null<IntervalPrice>
{
public:
Null() = default;
operator IntervalPrice() const { return {}; }
};

#endif

}

#endif
12 changes: 12 additions & 0 deletions ql/time/date.hpp
Expand Up @@ -370,12 +370,24 @@ namespace QuantLib {

}

#ifdef QL_NULL_AS_FUNCTIONS

//! specialization of Null template for the Date class
template <>
inline Date Null<Date>() {
return {};
}

#else

template <>
class Null<Date> {
public:
Null() = default;
operator Date() const { return {}; }
};

#endif

#ifndef QL_HIGH_RESOLUTION_DATE
// inline definitions
Expand Down
5 changes: 5 additions & 0 deletions ql/userconfig.hpp
Expand Up @@ -101,6 +101,11 @@
//# define QL_USE_STD_TUPLE
#endif

/* Define this to enable the implementation of Null as template functions. */
#ifndef QL_NULL_AS_FUNCTIONS
//# define QL_NULL_AS_FUNCTIONS
#endif

/* Define this to enable the parallel unit test runner */
#ifndef QL_ENABLE_PARALLEL_UNIT_TEST_RUNNER
//# define QL_ENABLE_PARALLEL_UNIT_TEST_RUNNER
Expand Down
22 changes: 20 additions & 2 deletions ql/utilities/null.hpp
Expand Up @@ -32,8 +32,6 @@

namespace QuantLib {



namespace detail {

template <bool>
Expand All @@ -59,12 +57,32 @@ namespace QuantLib {

}

#ifdef QL_NULL_AS_FUNCTIONS

//! template function providing a null value for a given type.
template <typename T>
T Null() {
return T(detail::FloatingPointNull<std::is_floating_point<T>::value>::nullValue());
}

#else

//! template class providing a null value for a given type.
template <class Type>
class Null;

// default implementation for built-in types
template <typename T>
class Null {
public:
Null() = default;
operator T() const {
return T(detail::FloatingPointNull<std::is_floating_point<T>::value>::nullValue());
}
};

#endif

}


Expand Down

0 comments on commit 1f9b454

Please sign in to comment.