Migrate ext::optional to std::optional (C++17 modernization)#1
Migrate ext::optional to std::optional (C++17 modernization)#1tobydrinkall wants to merge 4 commits into
Conversation
Replace ext::optional/ext::nullopt with std::optional/std::nullopt and switch #include <ql/optional.hpp> to #include <optional> across the library. Safe because QL_USE_STD_OPTIONAL defaulted to ON, so ext::optional was already an alias for std::optional. Co-Authored-By: Toby Drinkall <toby.drinkall@cognition.ai>
Co-Authored-By: Toby Drinkall <toby.drinkall@cognition.ai>
ql/optional.hpp now just includes <optional> with a deprecation note. Removes the now-dead boost::optional branch and the Boost 1.91 #error landmine. Drops the QL_USE_STD_OPTIONAL option from CMake, autotools, userconfig and CI alt-configs. Co-Authored-By: Toby Drinkall <toby.drinkall@cognition.ai>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
There was a problem hiding this comment.
Devin Review found 1 potential issue.
⚠️ 1 issue in files not directly in the diff
⚠️ CMakePresets.json still references removed QL_USE_STD_OPTIONAL option (CMakePresets.json:306)
The PR removes the QL_USE_STD_OPTIONAL CMake option from CMakeLists.txt (line 67 was deleted), but CMakePresets.json still sets "QL_USE_STD_OPTIONAL": "OFF" in two CI preset configurations (lines 306 and 326). These presets (linux-ci-build-with-nonstandard-options and windows-ci-build-with-nonstandard-options) were intended to test the library with boost::optional instead of std::optional. Since the option no longer exists in the build system, these settings silently become no-ops — CMake will create an unused cache variable without erroring. The CI builds using these presets no longer actually test a distinct configuration as intended.
View 3 additional findings in Devin Review.
The QL_USE_STD_OPTIONAL option was removed from the build system in this PR; the two CI presets (linux/windows -ci-build-with-nonstandard-options) that set it to OFF are now no-op cache variables. Removes them. Co-Authored-By: Toby Drinkall <toby.drinkall@cognition.ai>
|
Addressed the Devin Review finding on |
Summary
Replaces the deprecated
QuantLib::ext::optionalcompatibility shim with standard C++17std::optionalacross the library, test suite, and build configuration, and removes theQL_USE_STD_OPTIONALflag entirely.Why:
ql/optional.hppmappedext::optionalto eitherboost::optionalorstd::optionalbehind theQL_USE_STD_OPTIONALflag. The Boost branch carried a latent correctness landmine — the header literally#errors on Boost ≥ 1.91 because "Boost 1.91 introduced changes in boost::optional that silently changed the behavior of our code and would cause it to work incorrectly." In a pricing library, a dependency bump silently changingoptionalsemantics can change results. This migration eliminates that risk permanently.Why it's safe:
QL_USE_STD_OPTIONALalready defaulted to ON, soext::optionalwas already an alias forstd::optional— the change is type-identical (same ABI), purely removing the indirection.What changed (by layer)
Mechanical replacements:
ql/optional.hppis reduced to a thin, deprecated#include <optional>(back-compat for downstream includers). The now-deadQL_USE_STD_OPTIONALoption is dropped fromCMakeLists.txt,configure.ac,ql/userconfig.hpp,ql/config.hpp.cfg, the.ci/userconfig*.alt.hppconfigs, andDocs/pages/config.docs.Verification
config.hppno longer definesQL_USE_STD_OPTIONAL).autoreconf -isucceeds (autotools config still valid).Drafted as a demo artifact; commits are split into library / test-suite / build-flag-removal for reviewability.
Link to Devin session: https://app.devin.ai/sessions/d91f129a213241188cf4768afe9d6e1b
Requested by: @tobydrinkall
Devin Review