|
| 1 | +# beman.optional: C++26 Extensions for std::optional |
| 2 | + |
| 3 | +<!-- |
| 4 | +SPDX-License-Identifier: 2.0 license with LLVM exceptions |
| 5 | +--> |
| 6 | + |
| 7 | +import Godbolt from '@site/src/components/GenericFeatures/Godbolt.jsx' |
| 8 | + |
| 9 | + |
| 10 | +<!-- markdownlint-disable --> |
| 11 | +<img src="https://raw.githubusercontent.com/bemanproject/beman/refs/heads/main/images/logos/beman_logo-beman_library_production_ready_api_may_undergo_changes.png" width="5%" height="auto" />  [](https://coveralls.io/github/bemanproject/optional?branch=main) |
| 12 | +<!-- markdownlint-enable --> |
| 13 | + |
| 14 | +This repository implements `std::optional` extensions targeting C++26. The `beman.optional` library aims to evaluate the stability, the usability, and the performance of these proposed changes before they are officially adopted by WG21 into the C++ Working Draft. Additionally, it allows developers to use these new features before they are implemented in major standard library compilers. |
| 15 | + |
| 16 | +**Implements**: [Give *std::optional* Range Support (P3168R2)](https://wg21.link/P3168R2) and [`std::optional<T&>` (P2988R5)](https://wg21.link/P2988R5) |
| 17 | + |
| 18 | +**Status**: [Production ready. API may undergo changes.](../../BEMAN_LIBRARY_MATURITY_MODEL.md#production-ready-api-may-undergo-changes) |
| 19 | + |
| 20 | +## License |
| 21 | + |
| 22 | +Source is licensed with the Apache 2.0 license with LLVM exceptions |
| 23 | + |
| 24 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 25 | + |
| 26 | +Documentation and associated papers are licensed with the Creative Commons Attribution 4.0 International license. |
| 27 | + |
| 28 | +// SPDX-License-Identifier: CC-BY-4.0 |
| 29 | + |
| 30 | +The intent is that the source and documentation are available for use by people implementing their own optional types as well as people using the optional presented here as-is. |
| 31 | + |
| 32 | +The README itself is licensed with CC0 1.0 Universal. Copy the contents and incorporate in your own work as you see fit. |
| 33 | + |
| 34 | +// SPDX-License-Identifier: CC0-1.0 |
| 35 | + |
| 36 | +## Examples |
| 37 | + |
| 38 | +Full runnable examples can be found in `examples/` - please check [./examples/README.md](https://github.com/bemanproject/optional/blob/main/examples/README.md). |
| 39 | + |
| 40 | +### range_loop |
| 41 | + |
| 42 | +The next code snippet shows optional range support added in [Give *std::optional* Range Support(P3168R2)](https://wg21.link/P3168R2): |
| 43 | + |
| 44 | +```cpp |
| 45 | +#include <beman/optional/optional.hpp> |
| 46 | +... |
| 47 | + |
| 48 | +beman::optional::optional<int> empty_opt{}; |
| 49 | +for ([[maybe_unused]] const auto& i : empty_opt) { |
| 50 | + // Should not see this in console. |
| 51 | + std::cout << "\"for each loop\" over C++26 optional: empty_opt\n"; |
| 52 | +} |
| 53 | + |
| 54 | +beman::optional::optional<int> opt{26}; |
| 55 | +for (const auto& i : opt) { |
| 56 | + // Should see this in console. |
| 57 | + std::cout << "\"for each loop\" over C++26 optional: opt = " << i << "\n"; |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +Full code can be found in [./examples/range_loop.cpp](https://github.com/bemanproject/optional/blob/main/examples/range_loop.cpp). Build and run instructions in |
| 62 | +[./examples/README.md](https://github.com/bemanproject/optional/blob/main/examples/README.md). Or try it on Compiler Explorer: |
| 63 | +<Godbolt readOnly={false} url="https://godbolt.org/#z:OYLghAFBqd5QCxAYwPYBMCmBRdBLAF1QCcAaPECAMzwBtMA7AQwFtMQByARg9KtQYEAysib0QXACx8BBAKoBnTAAUAHpwAMvAFYTStJg1DIApACYAQuYukl9ZATwDKjdAGFUtAK4sGIMxqkrgAyeAyYAHI%2BAEaYxCAArKQADqgKhE4MHt6%2B/oGp6Y4CoeFRLLHxSXaYDplCBEzEBNk%2BfgG2mPZFDPWNBCWRMXGJtg1NLbntCmP9YYPlwwkAlLaoXsTI7BwA9NsA1JiqrMn0CtvEhsCYAPq0qKjJAHTIycl7ALQAVO9u1tZf7xMGgAgrs9kJlAARAAa71CmwYSneAEksII8DRhntgckmMgEJh3mZHho9gB1ZEAFQAEntgsEAGoAWXeh02yW6QOBXPMAGYwshvFg9iZeW5YixDNsHt0xNKOZkxI8EK9RdgeWZ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GYsabl2aJBW7FJBaDH3JWbC0g2bc2gpSRG0g2suAaECCLfV2jGOhOY5RdIzhJBAA%3D%3D" /> |
| 64 | + |
| 65 | +### optional_ref |
| 66 | + |
| 67 | +The next code snippet shows optional reference support added in [`std::optional<T&>` |
| 68 | +(P2988)](https://wg21.link/P2988): |
| 69 | + |
| 70 | +```cpp |
| 71 | +#include <beman/optional/optional.hpp> |
| 72 | +... |
| 73 | + |
| 74 | +struct Cat { ... }; |
| 75 | + |
| 76 | +beman::optional::optional<Cat&> find_cat(std::string) { return {}; } |
| 77 | +beman::optional::optional<Cat&> do_it(Cat& cat) { return { cat }; } |
| 78 | + |
| 79 | +beman::optional::optional<Cat&> api() { |
| 80 | + beman::optional::optional<Cat&> cat = find_cat("Fido"); |
| 81 | + return cat.and_then(do_it); |
| 82 | +} |
| 83 | + |
| 84 | +beman::optional::optional<Cat&> cat = api(); |
| 85 | + |
| 86 | +``` |
| 87 | +
|
| 88 | +Full code can be found in [./examples/optional_ref.cpp](https://github.com/bemanproject/optional/blob/main/examples/optional_ref.cpp). Build and run instructions in [./examples/README.md](https://github.com/bemanproject/optional/blob/main/examples/README.md). Or try it on Compiler Explorer: |
| 89 | +
|
| 90 | +<Godbolt url="https://godbolt.org/#z:OYLghAFBqd5QCxAYwPYBMCmBRdBLAF1QCcAaPECAMzwBtMA7AQwFtMQByARg9KtQYEAysib0QXACx8BBAKoBnTAAUAHpwAMvAFYTStJg1DIApACYAQuYukl9ZATwDKjdAGFUtAK4sGe1wAyeAyYAHI%2BAEaYxCAA7KQADqgKhE4MHt6%2BekkpjgJBIeEsUTHxdpgOaUIETMQEGT5%2BXLaY9nkM1bUEBWGR0XG2NXUNWc0KQ93BvcX9sQCUtqhexMjsHAD06wDUmKqsCfQK66gJ7WIA%2BsSYVAB0yAkJWwC0AFRPbtbWr08mGgCCmy2QmUABEABpPIKrBhKJ4ASSwgjwNH6Wz%2BCSYyAQmCeZhuGi2AHU4QAVAASWwCAQAagBZJ67VanNK/P6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eCmZuYfXRCWf6yAgbI7BswFsnZAaI1EKOQ%2BhgG7eXcATdc5N2K01PIzdO7Nuafl/IBRAZ1oKy1bChZW2Fo760LEbf0DF/bkG4vxR22jXbSUIoUZS9R1L6OzvpYy0j8TLEcoMFy5ly6EnbsFXUkVxbD1BOPaE4l26YmXrI5gm9Krr3TvVbk0p2qikSDfbIA1lTMG6HzKav95qAPWttQ3QwnTQO9JAM64ZUG3UTLgwhiqyGsG%2BuWfhoNeAQ14YwwRw5YxiMqfjaQRNNzyMtpo8Ol5Cn0yMfzTyOpRaBl4VLeazjFaYWzJrbxxF/HMCosEy20T/bO3Eu7XWrrpBMUiOQYOobnXKHYrMG2glEniXSaRdQrgGhJucGm8t2bSLekpGcJIIAA%3D%3D%3D" /> |
| 91 | +
|
| 92 | +## How to Build |
| 93 | +
|
| 94 | +### Compiler Support |
| 95 | +
|
| 96 | +This is a modern C++ project which can be compiled with the latest C++ standards (**C++20 or later**). |
| 97 | +
|
| 98 | +Default build: `C++23`. Please check `etc/${compiler}-flags.cmake`. |
| 99 | +
|
| 100 | +### Dependencies |
| 101 | +
|
| 102 | +This project is mainly tested on `Ubuntu 22.04` and `Ubuntu 24.04`, but it should be as portable as CMake is. This project has no C or C++ dependencies. |
| 103 | +
|
| 104 | +Build-time dependencies: |
| 105 | +
|
| 106 | +* `cmake` |
| 107 | +* `ninja`, `make`, or another CMake-supported build system |
| 108 | + * CMake defaults to "Unix Makefiles" on POSIX systems |
| 109 | +
|
| 110 | +Example of installation on `Ubuntu 24.04`: |
| 111 | +
|
| 112 | +```shell |
| 113 | +# Install tools: |
| 114 | +apt-get install -y cmake make ninja-build |
| 115 | +
|
| 116 | +# Example of toolchains: |
| 117 | +apt-get install \ |
| 118 | + g++-14 gcc-14 gcc-13 g++-13 \ |
| 119 | + clang-18 clang++-18 clang-17 clang++-17 |
| 120 | +``` |
| 121 | + |
| 122 | +<details> |
| 123 | +<summary> Build GoogleTest dependency from github.com </summary> |
| 124 | + |
| 125 | +If you do not have GoogleTest installed on your development system, you may |
| 126 | +optionally configure this project to download a known-compatible release of |
| 127 | +GoogleTest from source and build it as well. |
| 128 | + |
| 129 | +```shell |
| 130 | +cmake -B build -S . -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=./cmake/use-fetch-content.cmake |
| 131 | +``` |
| 132 | + |
| 133 | +The precise version of GoogleTest that will be used is maintained in |
| 134 | +`./lockfile.json`. |
| 135 | + |
| 136 | +</details> |
| 137 | + |
| 138 | +### Instructions |
| 139 | + |
| 140 | +Full set of supported toolchains can be found in [.github/workflows/ci.yml](https://github.com/bemanproject/optional/blob/main/.github/workflows/ci.yml). |
| 141 | + |
| 142 | +#### Preset CMake Flows |
| 143 | + |
| 144 | +This project strives to be as normal and simple a CMake project as possible. This build workflow in particular will work, producing a static `beman_optional` library, ready to package: |
| 145 | + |
| 146 | +```shell |
| 147 | +# List available preset configurations: |
| 148 | +$ cmake --workflow --list-presets |
| 149 | +Available workflow presets: |
| 150 | + |
| 151 | + "system" |
| 152 | + "gcc-14" |
| 153 | + "gcc-13" |
| 154 | + "clang-18" |
| 155 | + "clang-17" |
| 156 | + |
| 157 | +# Run examples: |
| 158 | +$ cmake --workflow --preset gcc-14 |
| 159 | +cmake --workflow --preset gcc-14 |
| 160 | +Executing workflow step 1 of 3: configure preset "gcc-14" |
| 161 | +... |
| 162 | +-- Build files have been written to: /path/to/repo/.build/gcc-14 |
| 163 | + |
| 164 | +Executing workflow step 2 of 3: build preset "gcc-14" |
| 165 | + |
| 166 | +ninja: no work to do. |
| 167 | + |
| 168 | +Executing workflow step 3 of 3: test preset "gcc-14" |
| 169 | + |
| 170 | +Test project /path/to/repo/.build/gcc-14 |
| 171 | + Start 1: OptionalTest.TestGTest |
| 172 | + 1/... Test #1: OptionalTest.TestGTest ........................... Passed 0.00 sec |
| 173 | +... |
| 174 | + Start x: RangeSupportTest.RangeConcepts |
| 175 | +.../... Test #x: RangeSupportTest.RangeConcepts ................... Passed 0.00 sec |
| 176 | + Start x+1: RangeSupportTest.IteratorConcepts |
| 177 | +.../... Test #x+1: RangeSupportTest.IteratorConcepts ................ Passed 0.00 sec |
| 178 | +... |
| 179 | + |
| 180 | +100% tests passed, 0 tests failed out of ... |
| 181 | + |
| 182 | +Total Test time (real) = 0.09 sec |
| 183 | +``` |
| 184 | + |
| 185 | +This should build and run the tests with GCC 14 with the address and undefined behavior sanitizers enabled. |
| 186 | + |
| 187 | +#### Custom CMake Flows |
| 188 | + |
| 189 | +##### Build and Run Tests |
| 190 | + |
| 191 | +CI current build and test flows: |
| 192 | + |
| 193 | +```shell |
| 194 | +# Configure build: default build production code + tests (OPTIONAL_ENABLE_TESTING=ON by default). |
| 195 | +$ cmake -G "Ninja Multi-Config" \ |
| 196 | + -DCMAKE_CONFIGURATION_TYPES="RelWithDebInfo;Asan" \ |
| 197 | + -DCMAKE_TOOLCHAIN_FILE=etc/clang-19-toolchain.cmake \ |
| 198 | + -B .build -S . |
| 199 | +-- The CXX compiler identification is Clang 19.0.0 |
| 200 | +... |
| 201 | +-- Build files have been written to: /path/to/optional/.build |
| 202 | + |
| 203 | +# Build. |
| 204 | +$ cmake --build .build --config Asan --target all -- -k 0 |
| 205 | +... |
| 206 | +[30/30] Linking CXX executable ... # Note: 30 targets here (including tests). |
| 207 | + |
| 208 | +# Run tests. |
| 209 | +$ ctest --build-config Asan --output-on-failure --test-dir .build |
| 210 | +Internal ctest changing into directory: /path/to/optional/.build |
| 211 | +Test project /path/to/optional/.build |
| 212 | +... |
| 213 | +100% tests passed, 0 tests failed out of 82 |
| 214 | + |
| 215 | +Total Test time (real) = 0.67 sec |
| 216 | +``` |
| 217 | + |
| 218 | +##### Build Production, but Skip Tests |
| 219 | + |
| 220 | +By default, we build and run tests. You can provide `-DOPTIONAL_ENABLE_TESTING=OFF` and completely disable building tests: |
| 221 | + |
| 222 | +```shell |
| 223 | +# Configure build: build production code, skip tests (OPTIONAL_ENABLE_TESTING=OFF). |
| 224 | +$ cmake -G "Ninja Multi-Config" \ |
| 225 | + -DCMAKE_CONFIGURATION_TYPES="RelWithDebInfo;Asan" \ |
| 226 | + -DCMAKE_TOOLCHAIN_FILE=etc/clang-19-toolchain.cmake \ |
| 227 | + -DOPTIONAL_ENABLE_TESTING=OFF \ |
| 228 | + -B .build -S . |
| 229 | +-- The CXX compiler identification is Clang 19.0.0 |
| 230 | +... |
| 231 | +-- Build files have been written to: /path/to/optional/.build |
| 232 | + |
| 233 | +# Build. |
| 234 | +$ cmake --build .build --config Asan --target all -- -k 0 |
| 235 | +... |
| 236 | +[15/15] Linking CXX executable ... # Note: 15 targets here (tests were not built). |
| 237 | + |
| 238 | +# Check that tests are not built/installed. |
| 239 | +$ ctest --build-config Asan --output-on-failure --test-dir .build |
| 240 | +Internal ctest changing into directory: /path/to/beman.optional/.build |
| 241 | +Test project /path/to/beman.optional/.build |
| 242 | +No tests were found!!! |
| 243 | +``` |
| 244 | + |
| 245 | +#### Pre-Commit for Linting |
| 246 | + |
| 247 | +Various linting tools are configured and installed via the [pre-commit](https://pre-commit.com/) framework. This requires a working python environment, but also allows the tools, such as clang-format and cmake-lint, to be versioned on a per project basis rather than being installed globally. Version changes in lint checks often means differences in success or failure between the versions in CI and the versions used by a developer. By using the same configurations, this problem is avoided. |
| 248 | + |
| 249 | +In order to set up a python environment, using a python virtual environment can simplify maintaining different configurations between projects. There is no particular dependency on a particular python3 version. |
| 250 | + |
| 251 | +##### Creating and configuring a venv |
| 252 | + |
| 253 | +```shell |
| 254 | +python3 -m venv .venv |
| 255 | +. .venv/bin/activate && python3 -m pip install --upgrade pip setuptools wheel |
| 256 | +. .venv/bin/activate && python3 -m pip install pip-tools |
| 257 | +. .venv/bin/activate && python3 -m piptools sync requirements.txt |
| 258 | +. .venv/bin/activate && python3 -m piptools sync requirements-dev.txt |
| 259 | +. .venv/bin/activate && exec bash |
| 260 | +``` |
| 261 | + |
| 262 | +This will create the venv, install the python and python development tools, and run bash with the PATH and other environment variables set to use the venv preferentially. |
| 263 | + |
| 264 | +##### Running the linting tools |
| 265 | + |
| 266 | +```shell |
| 267 | +pre-commit run -a |
| 268 | +``` |
| 269 | + |
| 270 | +This will download and configure the lint tools specified in .pre-commit-config.yaml. |
| 271 | + |
| 272 | +There is also a Makefile that will automate this process and keep everything up to date. |
| 273 | + |
| 274 | +```shell |
| 275 | +make lint |
| 276 | +``` |
| 277 | + |
| 278 | +## Papers |
| 279 | + |
| 280 | +Latest revision(s) of the papers can be built / found at: |
| 281 | + |
| 282 | +* [give-std-optional-range-support](https://github.com/neatudarius/give-std-optional-range-support/) for |
| 283 | +`Give *std::optional* Range Support (P3168)` |
| 284 | + * issue: [#1831](https://github.com/cplusplus/papers/issues/1831) |
| 285 | + * LEWG: |
| 286 | + * Reviewed in Tokyo 2024. |
| 287 | + * Forwarded by LEWG April electronic poll to LWG. |
| 288 | + * LWG: |
| 289 | + * Reviewed and approved in Saint Louis 2024. |
| 290 | +* [./papers/P2988/README.md](https://github.com/bemanproject/optional/blob/main/papers/P2988/README.md) for `std::optional<T&> (P2988)`. |
| 291 | + * issue: [#1661](https://github.com/cplusplus/papers/issues/1661) |
| 292 | + * LEWG: |
| 293 | + * Reviewed in Tokyo 2024. |
| 294 | + * Forwarded by LEWG in 2025 in Hagenberg. |
0 commit comments