Skip to content

refactor: migrate ext::optional to std::optional, remove QL_USE_STD_OPTIONAL#2

Open
tobydrinkall wants to merge 5 commits into
masterfrom
devin/1780659422-migrate-std-optional
Open

refactor: migrate ext::optional to std::optional, remove QL_USE_STD_OPTIONAL#2
tobydrinkall wants to merge 5 commits into
masterfrom
devin/1780659422-migrate-std-optional

Conversation

@tobydrinkall
Copy link
Copy Markdown

@tobydrinkall tobydrinkall commented Jun 5, 2026

Summary

Complete migration from ext::optional/ext::nullopt to std::optional/std::nullopt across the entire codebase. The ext:: aliases were a compatibility shim mapping to either boost::optional or std::optional depending on QL_USE_STD_OPTIONAL. Since C++17 is now required (CMAKE_CXX_STANDARD 17), the indirection is unnecessary.

Structured commits

1. refactor: mechanical text replacements (80 files, ±345 lines)

ext::optional<T>           →  std::optional<T>
ext::nullopt               →  std::nullopt
#include <ql/optional.hpp>  →  #include <optional>

No functional change — with QL_USE_STD_OPTIONAL=ON (the default), ext::optional was already a using declaration for std::optional.

2. build: remove QL_USE_STD_OPTIONAL from build configuration (9 files, −60 lines)

  • CMakeLists.txtoption() + QL_USE_STD_CLASSES shortcut
  • configure.ac--enable-std-optional block + --enable-std-classes define
  • CMakePresets.json — two preset cache entries
  • ql/userconfig.hpp, ql/config.hpp.cfg#define / #cmakedefine
  • .ci/userconfig{2019,2022,2026}.alt.hpp — conditional #define blocks
  • Docs/pages/config.docs — documentation paragraph

After commit 1, no source references ext::optional, so the toggle is dead code.

3. deprecate: simplify ql/optional.hpp to a forwarding header

Replaces the conditional boost/std dispatch with:

  • #pragma message deprecation warning
  • Unconditional #include <optional>
  • Retained QuantLib::ext:: aliases for downstream compatibility

4–5. fix: umbrella header cleanup

Per review feedback: removed ql/optional.hpp from the auto-generated umbrella header (cmake/GenerateHeaders.cmake exclusion + ql/quantlib.hpp edit) to avoid noisy deprecation warnings, while keeping the header installable in both CMake and autotools for backward compatibility.

Dependency ordering

Each phase is independently buildable:

  • Commit 1 works because QL_USE_STD_OPTIONAL=ON (default) meant ext::optional was already std::optional
  • Commit 2 works because no source references the macro after commit 1
  • Commit 3 works because ql/optional.hpp is only included via ql/quantlib.hpp (the umbrella header) after commit 1
  • Commits 4–5 ensure the deprecation #pragma doesn't fire through the umbrella header

Verification

  • Full clean build (Release, GCC 11, Boost 1.74) succeeds with zero warnings
  • Full ctest suite: 100% tests passed (284s, identical to 287s baseline)
  • All cached pricing tests (NPV, Greeks, term structures) produce identical results

Link to Devin session: https://app.devin.ai/sessions/4b1b94a613fe4adfaa8868760eaff1ff
Requested by: @tobydrinkall


Devin Review

Status Commit
⚪ Not started

Run Devin Review

Open in Devin Review (Staging)
Open in Devin Review

devin-ai-integration Bot and others added 3 commits June 5, 2026 11:47
…nullopt

Mechanical text replacements across 80 source files:
- ext::optional<T> -> std::optional<T>
- ext::nullopt -> std::nullopt
- #include <ql/optional.hpp> -> #include <optional>

The ext:: aliases were a compatibility shim mapping to either
boost::optional or std::optional depending on QL_USE_STD_OPTIONAL.
Since std::optional is now universally available (C++17), all call
sites are updated to use the standard type directly.

No functional changes: with QL_USE_STD_OPTIONAL=ON (the default),
ext::optional was already a using-declaration for std::optional.

Co-Authored-By: Toby Drinkall <toby.drinkall@cognition.ai>
Remove the QL_USE_STD_OPTIONAL toggle from all build system files:
- CMakeLists.txt: option() declaration and QL_USE_STD_CLASSES shortcut
- configure.ac: --enable-std-optional AC_ARG_ENABLE block and std-classes define
- CMakePresets.json: two preset cache variable entries
- ql/userconfig.hpp: #define block and documentation comment
- ql/config.hpp.cfg: #cmakedefine line
- .ci/userconfig{2019,2022,2026}.alt.hpp: conditional #define blocks
- Docs/pages/config.docs: documentation paragraph

After commit 1, no code references ext::optional — all call sites use
std::optional directly. The conditional compilation gate is dead code.
ql/optional.hpp still compiles (it reads QL_USE_STD_OPTIONAL) but will
be simplified in the next commit.

Co-Authored-By: Toby Drinkall <toby.drinkall@cognition.ai>
Replace the conditional boost/std dispatch with a plain forwarding
header that:
- Emits a #pragma message deprecation warning on inclusion
- Includes <optional> unconditionally
- Retains the QuantLib::ext:: aliases for downstream compatibility

The boost::optional code path and QL_USE_STD_OPTIONAL guard are
removed. Third-party code that includes <ql/optional.hpp> or uses
ext::optional will still compile but will see the deprecation
warning guiding them to migrate to std::optional.

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

devin-ai-integration[bot]

This comment was marked as resolved.

…ion warning

Remove ql/optional.hpp from ql/Makefile.am and ql/quantlib.hpp so
that the #pragma message deprecation warning does not fire for every
translation unit that includes the umbrella header.

The deprecated ql/optional.hpp remains available for explicit
inclusion by downstream code that hasn't migrated yet.

Co-Authored-By: Toby Drinkall <toby.drinkall@cognition.ai>
devin-ai-integration[bot]

This comment was marked as resolved.

…brella header

Restore optional.hpp to ql/Makefile.am so autotools still installs it
(matching ql/CMakeLists.txt). Add an exclusion in GenerateHeaders.cmake
so the CMake-generated ql/quantlib.hpp skips it.

Both build systems now:
- Install the deprecated header (backward compat for downstream code)
- Exclude it from the umbrella header (no noisy #pragma warnings)

Co-Authored-By: Toby Drinkall <toby.drinkall@cognition.ai>
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