You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+84-3Lines changed: 84 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,16 @@
1
1
# Beman.Optional26: C++26 Extensions for std::optional
2
2
3
+
<!--
4
+
SPDX-License-Identifier: 2.0 license with LLVM exceptions
5
+
-->
6
+
3
7
This implementation incorporates the C++26 extensions added for `std::optional`. The `Beman.Optional26` 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.
4
8
5
9
**Implements**:
10
+
*[Give *std::optional* Range Support (P3168R1)](https://wg21.link/P3168R1)
*[Give *std::optional* Range Support (P3168R1)](https://wg21.link/P3168R1).
8
12
13
+
## License
9
14
10
15
Source is licensed with the Apache 2.0 license with LLVM exceptions
11
16
@@ -21,8 +26,74 @@ The README itself is licesed with CC0 1.0 Universal. Copy the contents and incor
21
26
22
27
// SPDX-License-Identifier: CC0-1.0
23
28
29
+
## Examples
30
+
31
+
Full runable examples can be found in `examples/` - please check [./examples/README.md](./examples/README.md).
32
+
33
+
### range_loop
34
+
35
+
The next code snippet shows optional range support added in [Give *std::optional* Range Support (P3168R1)](https://wg21.link/P3168R1):
36
+
37
+
```cpp
38
+
#include<Beman/Optional26/optional.hpp>
39
+
...
40
+
41
+
// Example from P3168R1: basic range loop over C++26 optional.
42
+
43
+
beman::optional26::optional<int> empty_opt{};
44
+
for ([[maybe_unused]] constauto& i : empty_opt) {
45
+
// Should not see this in console.
46
+
std::cout << "\"for each loop\" over C++26 optional: empty_opt\n";
47
+
}
48
+
49
+
beman::optional26::optional<int> opt{26};
50
+
for (const auto& i : opt) {
51
+
// Should see this in console.
52
+
std::cout << "\"for each loop\" over C++26 optional: opt = " << i << "\n";
53
+
}
54
+
```
55
+
56
+
Full code can be found in [./examples/range_loop.cpp](./examples/range_loop.cpp). Build and run instructions in [./examples/README.md](./examples/README.md).
57
+
58
+
### optional_ref
59
+
60
+
The next code snippet shows optional reference support added in [`std::optional<T&>` (P2988R5)](https://wg21.link/P2988R5):
61
+
62
+
```cpp
63
+
#include<Beman/Optional26/optional.hpp>
64
+
...
65
+
66
+
{
67
+
// Empty optional example.
68
+
std::optional<int> std_empty_opt;
69
+
beman::optional26::optional<int> beman_empty_opt;
70
+
assert(!std_empty_opt.has_value() &&
71
+
!beman_empty_opt.has_value()); // or assert(!std_empty_opt && !beman_empty_opt);
Full code can be found in [./examples/optional_ref.cpp](./examples/optional_ref.cpp). Build and run instructions in [./examples/README.md](./examples/README.md).
88
+
24
89
## How to Build
25
90
91
+
### Compiler Support
92
+
93
+
This is a modern C++ project which can be compiled with the latest C++ standards (**C++20 or later**).
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 zero C or C++ dependencies.
@@ -52,6 +123,8 @@ This project strives to be as normal and simple a CMake project as possible. Thi
52
123
53
124
```shell
54
125
cmake --workflow --preset gcc-14
126
+
cmake --workflow --preset clang-18
127
+
cmake --workflow --preset systems # uses c++ set tool
55
128
```
56
129
57
130
This should build and run the tests with GCC 14 with the address and undefined behavior sanitizers enabled.
@@ -69,6 +142,14 @@ The makefile will use your system compiler, `c++`, if no toolchain name is provi
69
142
## Papers
70
143
71
144
Latest revision(s) of the papers can be built / found at:
72
-
*[./papers/P2988/README.md](./papers/P2988/README.md) for `std::optional<T&> (P2988)`.
73
145
*[give-std-optional-range-support](https://github.com/neatudarius/give-std-optional-range-support/) for `Give *std::optional* Range Support (P3168)`
SPDX-License-Identifier: 2.0 license with LLVM exceptions
5
+
-->
6
+
3
7
List of usage examples for `Beman.Optional26`.
4
8
9
+
## License
10
+
Source is licensed with the Apache 2.0 license with LLVM exceptions
11
+
12
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
13
+
14
+
Documentation and associated papers are licensed with the Creative Commons Attribution 4.0 International license.
15
+
16
+
// SPDX-License-Identifier: CC-BY-4.0
17
+
18
+
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.
19
+
20
+
The README itself is licesed with CC0 1.0 Universal. Copy the contents and incorporate in your own work as you see fit.
21
+
22
+
// SPDX-License-Identifier: CC0-1.0
23
+
5
24
## Sample
6
25
7
26
Check [sample](sample.cpp) for basic `Beman.Optional26` library usage.
0 commit comments