Skip to content

Migrate ext::optional to std::optional (C++17 modernization)#1

Open
tobydrinkall wants to merge 4 commits into
masterfrom
migrate-ext-optional-to-std-optional
Open

Migrate ext::optional to std::optional (C++17 modernization)#1
tobydrinkall wants to merge 4 commits into
masterfrom
migrate-ext-optional-to-std-optional

Conversation

@tobydrinkall
Copy link
Copy Markdown

@tobydrinkall tobydrinkall commented Jun 5, 2026

Summary

Replaces the deprecated QuantLib::ext::optional compatibility shim with standard C++17 std::optional across the library, test suite, and build configuration, and removes the QL_USE_STD_OPTIONAL flag entirely.

Why: ql/optional.hpp mapped ext::optional to either boost::optional or std::optional behind the QL_USE_STD_OPTIONAL flag. 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 changing optional semantics can change results. This migration eliminates that risk permanently.

Why it's safe: QL_USE_STD_OPTIONAL already defaulted to ON, so ext::optional was already an alias for std::optional — the change is type-identical (same ABI), purely removing the indirection.

What changed (by layer)

ql/** library headers + sources ... 72 files   ext::optional → std::optional
test-suite/** .................... 9 files     ext::nullopt  → std::nullopt
build/config/shim ................ 9 files     #include <ql/optional.hpp> → <optional>

Mechanical replacements:

ext::optional<T>            -> std::optional<T>          (262 occurrences)
ext::nullopt               -> std::nullopt              (131 occurrences)
#include <ql/optional.hpp>  -> #include <optional>       (53 files)

ql/optional.hpp is reduced to a thin, deprecated #include <optional> (back-compat for downstream includers). The now-dead QL_USE_STD_OPTIONAL option is dropped from CMakeLists.txt, configure.ac, ql/userconfig.hpp, ql/config.hpp.cfg, the .ci/userconfig*.alt.hpp configs, and Docs/pages/config.docs.

Verification

  • Build: 100% (clean CMake configure + build; generated config.hpp no longer defines QL_USE_STD_OPTIONAL).
  • Test suite: 100% tests passed, 0 failed (full Boost.Test regression, ~285s) — i.e. pricing behavior unchanged.
  • autoreconf -i succeeds (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

Status Commit
⚪ Not started

Run Devin Review

Open in Devin Review (Staging)

devin-ai-integration Bot and others added 3 commits June 5, 2026 11:50
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-integration
Copy link
Copy Markdown

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@tobydrinkall tobydrinkall marked this pull request as ready for review June 5, 2026 12:52
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Open 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>
@devin-ai-integration
Copy link
Copy Markdown

Addressed the Devin Review finding on CMakePresets.json in 77e091e: removed the stale "QL_USE_STD_OPTIONAL": "OFF" entries from the linux-ci-build-with-nonstandard-options and windows-ci-build-with-nonstandard-options presets, since the option no longer exists in the build system (they would have become silent no-op cache variables). grep -rn QL_USE_STD_OPTIONAL is now clean outside build dirs, and the file still parses as valid JSON.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant