Skip to content

Commit 2a22fe7

Browse files
committed
Update readme (#5)
Remove `identity`
2 parents 7017568 + 0d3c1d0 commit 2a22fe7

1 file changed

Lines changed: 261 additions & 67 deletions

File tree

README.md

Lines changed: 261 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
1-
TODO
1+
# beman.expected: Expected Over References
2+
3+
<!--
4+
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
-->
6+
7+
<!-- markdownlint-disable-next-line line-length -->
8+
![Library Status](https://raw.githubusercontent.com/bemanproject/beman/refs/heads/main/images/badges/beman_badge-beman_library_under_development.svg) ![Continuous Integration Tests](https://github.com/steve-downey/expected/actions/workflows/ci_tests.yml/badge.svg) ![Lint Check (pre-commit)](https://github.com/steve-downey/expected/actions/workflows/pre-commit-check.yml/badge.svg) [![Coverage](https://coveralls.io/repos/github/steve-downey/expected/badge.svg?branch=main)](https://coveralls.io/github/steve-downey/expected?branch=main) ![Standard Target](https://github.com/bemanproject/beman/blob/main/images/badges/cpp29.svg) [![Compiler Explorer Example](https://img.shields.io/badge/Try%20it%20on%20Compiler%20Explorer-grey?logo=compilerexplorer&logoColor=67c52a)](https://www.example.com)
9+
10+
`beman.expected` is a C++ library implementing the std::expected specification conforming to [The Beman Standard](https://github.com/bemanproject/beman/blob/main/docs/beman_standard.md).
11+
12+
**Implements**: `std::expected` proposed in [Expected over References (PnnnnRr)](https://wg21.link/PnnnnRr).
13+
14+
**Status**: [Under development and not yet ready for production use.](https://github.com/bemanproject/beman/blob/main/docs/beman_library_maturity_model.md#under-development-and-not-yet-ready-for-production-use)
15+
16+
## License
17+
18+
`beman.expected` is licensed under the Apache License v2.0 with LLVM Exceptions.
19+
20+
## Usage
21+
222

323
Full runnable examples can be found in [`examples/`](examples/).
424

@@ -8,113 +28,241 @@ Full runnable examples can be found in [`examples/`](examples/).
828

929
This project requires at least the following to build:
1030

11-
* A C++ compiler that conforms to the C++20 standard or greater
12-
* CMake 3.30 or later
31+
* A C++ compiler that conforms to the C++17 standard or greater
32+
* CMake 3.28 or later
1333
* (Test Only) GoogleTest
1434

15-
You can disable building tests by setting CMake option `BEMAN_EXPECTED_BUILD_TESTS` to
16-
`OFF` when configuring the project.
35+
You can disable building tests by setting CMake option
36+
[`BEMAN_EXPECTED_BUILD_TESTS`](#beman_expected_build_tests) to `OFF`
37+
when configuring the project.
38+
39+
Even when tests are being built and run, some of them will not be compiled
40+
unless the provided compiler supports **C++20** ranges.
41+
42+
> [!TIP]
43+
>
44+
> The logs indicate examples disabled due to lack of compiler support.
45+
>
46+
> For example:
47+
>
48+
> ```txt
49+
> -- Looking for __cpp_lib_ranges
50+
> -- Looking for __cpp_lib_ranges - not found
51+
> CMake Warning at examples/CMakeLists.txt:12 (message):
52+
> Missing range support! Skip: identity_as_default_projection
53+
>
54+
>
55+
> Examples to be built: identity_direct_usage
56+
> ```
1757
1858
### Supported Platforms
1959
20-
| Compiler | Version | C++ Standards | Standard Library |
21-
|------------|---------|---------------|-------------------|
22-
| GCC | 16-13 | C++26-C++17 | libstdc++ |
23-
| GCC | 12-11 | C++23-C++17 | libstdc++ |
24-
| Clang | 22-19 | C++26-C++17 | libstdc++, libc++ |
25-
| Clang | 18 | C++26-C++17 | libc++ |
26-
| Clang | 18 | C++23-C++17 | libstdc++ |
27-
| Clang | 17 | C++26-C++17 | libc++ |
28-
| Clang | 17 | C++20, C++17 | libstdc++ |
29-
| AppleClang | latest | C++26-C++17 | libc++ |
30-
| MSVC | latest | C++23 | MSVC STL |
60+
This project officially supports:
61+
62+
* GCC versions 11–15
63+
* LLVM Clang++ (with libstdc++ or libc++) versions 17–21
64+
* AppleClang version 17.0.0 (i.e., the [latest version on GitHub-hosted macOS runners](https://github.com/actions/runner-images/blob/main/images/macos/macos-15-arm64-Readme.md))
65+
* MSVC version 19.44.35215.0 (i.e., the [latest version on GitHub-hosted Windows runners](https://github.com/actions/runner-images/blob/main/images/windows/Windows2022-Readme.md))
66+
67+
> [!NOTE]
68+
>
69+
> Versions outside of this range would likely work as well,
70+
> especially if you're using a version above the given range
71+
> (e.g. HEAD/ nightly).
72+
> These development environments are verified using our CI configuration.
3173
3274
## Development
3375
34-
See the [Contributing Guidelines](CONTRIBUTING.md).
76+
### Develop using GitHub Codespace
3577
36-
## Integrate beman.expected into your project
78+
This project supports [GitHub Codespace](https://github.com/features/codespaces)
79+
via [Development Containers](https://containers.dev/),
80+
which allows rapid development and instant hacking in your browser.
81+
We recommend using GitHub codespace to explore this project as it
82+
requires minimal setup.
83+
84+
Click the following badge to create a codespace:
85+
86+
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/bemanproject/expected)
3787
38-
### Build
88+
For more documentation on GitHub codespaces, please see
89+
[this doc](https://docs.github.com/en/codespaces/).
90+
91+
> [!NOTE]
92+
>
93+
> The codespace container may take up to 5 minutes to build and spin-up; this is normal.
3994
40-
You can build expected using a CMake workflow preset:
95+
### Develop locally on your machines
96+
97+
<details>
98+
<summary> For Linux </summary>
99+
100+
Beman libraries require [recent versions of CMake](#build-environment).
101+
We recommend one of:
102+
- downloading CMake directly from [CMake's website](https://cmake.org/download/)
103+
- installing it with the [Kitware apt library](https://apt.kitware.com/).
104+
- installing for the project using [Astral's uv](https://docs.astral.sh/uv/) and PyPI.
105+
106+
A [supported compiler](#supported-platforms) should be available from your package manager.
107+
108+
</details>
109+
110+
<details>
111+
<summary> For MacOS </summary>
112+
113+
Beman libraries require [recent versions of CMake](#build-environment).
114+
Use [`Homebrew`](https://brew.sh/) to install the latest version of CMake.
41115
42116
```bash
43-
cmake --workflow --preset gcc-release
117+
brew install cmake
44118
```
45119
46-
To list available workflow presets, you can invoke:
120+
A [supported compiler](#supported-platforms) is also available from brew.
121+
122+
For example, you can install the latest major release of Clang as:
47123

48124
```bash
49-
cmake --list-presets=workflow
125+
brew install llvm
50126
```
51127

52-
For details on building beman.expected without using a CMake preset, refer to the
53-
[Contributing Guidelines](CONTRIBUTING.md).
128+
</details>
54129

55-
### Installation
130+
<details>
131+
<summary> For Windows </summary>
56132

57-
#### Vcpkg
133+
To build Beman libraries, you will need the MSVC compiler. MSVC can be obtained
134+
by installing Visual Studio; the free Visual Studio 2022 Community Edition can
135+
be downloaded from
136+
[Microsoft](https://visualstudio.microsoft.com/vs/community/).
58137

59-
The preferred way to install expected is via vcpkg. To do so, after installing vcpkg
60-
itself, you need to add support for the Beman project's [vcpkg
61-
registry](https://github.com/bemanproject/vcpkg-registry) by configuring a
62-
`vcpkg-configuration.json` file (which expected [provides](vcpkg-configuration.json)).
138+
After Visual Studio has been installed, you can launch "Developer PowerShell for
139+
VS 2022" by typing it into Windows search bar. This shell environment will
140+
provide CMake, Ninja, and MSVC, allowing you to build the library and run the
141+
tests.
63142

64-
Then, simply run `vcpkg install beman-expected`.
143+
Note that you will need to use FetchContent to build GoogleTest. To do so,
144+
please see the instructions in the "Build GoogleTest dependency from github.com"
145+
dropdown in the [Project specific configure
146+
arguments](#project-specific-configure-arguments) section.
65147

66-
#### Manual
148+
</details>
67149

68-
To install beman.expected globally after building with the `gcc-release` preset, you can
69-
run:
150+
### Configure and Build the Project Using CMake Presets
70151

71-
```bash
72-
sudo cmake --install build/gcc-release
152+
This project recommends using [CMake Presets](https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html)
153+
to configure, build and test the project.
154+
Appropriate presets for major compilers have been included by default.
155+
You can use `cmake --list-presets` to see all available presets.
156+
157+
Here is an example to invoke the `gcc-debug` preset.
158+
159+
```shell
160+
cmake --workflow --preset gcc-debug
73161
```
74162

75-
Alternatively, to install to a prefix, for example `/opt/beman`, you can run:
163+
Generally, there are two kinds of presets, `debug` and `release`.
164+
165+
The `debug` presets are designed to aid development, so it has debugging
166+
instrumentation enabled and many sanitizers enabled.
167+
168+
> [!NOTE]
169+
>
170+
> The sanitizers that are enabled vary from compiler to compiler.
171+
> See the toolchain files under ([`cmake`](cmake/)) to determine the exact configuration used for each preset.
172+
173+
The `release` presets are designed for production use, and
174+
consequently have the highest optimization turned on (e.g. `O3`).
175+
176+
### Configure and Build Manually
177+
178+
If the presets are not suitable for your use-case, a traditional CMake
179+
invocation will provide more configurability.
180+
181+
To configure, build and test the project with extra arguments,
182+
you can run this set of commands.
76183

77184
```bash
78-
sudo cmake --install build/gcc-release --prefix /opt/beman
185+
cmake \
186+
-B build \
187+
-S . \
188+
-DCMAKE_CXX_STANDARD=20 \
189+
-DCMAKE_PREFIX_PATH=$PWD/infra/cmake \
190+
# Your extra arguments here.
191+
cmake --build build
192+
ctest --test-dir build
79193
```
80194

81-
This will generate the following directory structure:
82-
83-
```txt
84-
/opt/beman
85-
├── include
86-
│ └── beman
87-
│ └── expected
88-
│ ├── expected.hpp
89-
│ └── ...
90-
└── lib
91-
└── cmake
92-
└── beman.expected
93-
├── beman.expected-config-version.cmake
94-
├── beman.expected-config.cmake
95-
└── beman.expected-targets.cmake
195+
> [!IMPORTANT]
196+
>
197+
> Beman projects are
198+
> [passive projects](https://github.com/bemanproject/beman/blob/main/docs/beman_standard.md#cmake),
199+
> therefore,
200+
> you will need to specify the C++ version via `CMAKE_CXX_STANDARD`
201+
> when manually configuring the project.
202+
203+
### Finding and Fetching GTest from GitHub
204+
205+
If you do not have GoogleTest installed on your development system, you may
206+
optionally configure this project to download a known-compatible release of
207+
GoogleTest from source and build it as well.
208+
209+
Example commands:
210+
211+
```shell
212+
cmake -B build -S . \
213+
-DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=./infra/cmake/use-fetch-content.cmake \
214+
-DCMAKE_CXX_STANDARD=20
215+
cmake --build build --target all
216+
cmake --build build --target test
96217
```
97218

98-
### CMake Configuration
219+
The precise version of GoogleTest that will be used is maintained in
220+
`./lockfile.json`.
99221

100-
If you installed beman.expected to a prefix, you can specify that prefix to your CMake
101-
project using `CMAKE_PREFIX_PATH`; for example, `-DCMAKE_PREFIX_PATH=/opt/beman`.
222+
### Project specific configure arguments
102223

103-
You need to bring in the `beman.expected` package to define the `beman::expected` CMake
104-
target:
224+
Project-specific options are prefixed with `BEMAN_EXPECTED`.
225+
You can see the list of available options with:
105226

106-
```cmake
107-
find_package(beman.expected REQUIRED)
227+
```bash
228+
cmake -LH -S . -B build | grep "BEMAN_EXPECTED" -C 2
108229
```
109230

110-
You will then need to add `beman::expected` to the link libraries of any libraries or
111-
executables that include `beman.expected` headers.
231+
<details>
112232

113-
```cmake
114-
target_link_libraries(yourlib PUBLIC beman::expected)
233+
<summary> Details of CMake arguments. </summary>
234+
235+
#### `BEMAN_EXPECTED_BUILD_TESTS`
236+
237+
Enable building tests and test infrastructure. Default: ON.
238+
Values: `{ ON, OFF }`.
239+
240+
You can configure the project to have this option turned off via:
241+
242+
```bash
243+
cmake -B build -S . -DCMAKE_CXX_STANDARD=20 -DBEMAN_EXPECTED_BUILD_TESTS=OFF
115244
```
116245

117-
### Using beman.expected
246+
> [!TIP]
247+
> Because this project requires GoogleTest for running tests,
248+
> disabling `BEMAN_EXPECTED_BUILD_TESTS` avoids the project from
249+
> cloning GoogleTest from GitHub.
250+
251+
#### `BEMAN_EXPECTED_BUILD_EXAMPLES`
252+
253+
Enable building examples. Default: ON. Values: { ON, OFF }.
254+
255+
#### `BEMAN_EXPECTED_INSTALL_CONFIG_FILE_PACKAGE`
256+
257+
Enable installing the CMake config file package. Default: ON.
258+
Values: { ON, OFF }.
259+
260+
This is required so that users of `beman.expected` can use
261+
`find_package(beman.expected)` to locate the library.
262+
263+
</details>
264+
265+
## Integrate beman.expected into your project
118266

119267
To use `beman.expected` in your C++ project,
120268
include an appropriate `beman.expected` header from your source code.
@@ -127,4 +275,50 @@ include an appropriate `beman.expected` header from your source code.
127275
>
128276
> `beman.expected` headers are to be included with the `beman/expected/` prefix.
129277
> Altering include search paths to spell the include target another way (e.g.
130-
> `#include <expected.hpp>`) is unsupported.
278+
> `#include <identity.hpp>`) is unsupported.
279+
280+
The process for incorporating `beman.expected` into your project depends on the
281+
build system being used. Instructions for CMake are provided in following sections.
282+
283+
### Incorporating `beman.expected` into your project with CMake
284+
285+
For CMake based projects,
286+
you will need to use the `beman.expected` CMake module
287+
to define the `beman::expected` CMake target:
288+
289+
```cmake
290+
find_package(beman.expected REQUIRED)
291+
```
292+
293+
You will also need to add `beman::expected` to the link libraries of
294+
any libraries or executables that include `beman.expected` headers.
295+
296+
```cmake
297+
target_link_libraries(yourlib PUBLIC beman::expected)
298+
```
299+
300+
### Produce beman.expected interface library
301+
302+
You can produce expected's interface library locally by:
303+
304+
```bash
305+
cmake --workflow --preset gcc-release
306+
cmake --install build/gcc-release --prefix /opt/beman
307+
```
308+
309+
This will generate the following directory structure at `/opt/beman`.
310+
311+
```txt
312+
/opt/beman
313+
├── include
314+
│   └── beman
315+
│   └── expected
316+
│   ├── bad_expected_access.hpp
317+
│   ├── expected.hpp
318+
│   └── unexpected.hpp
319+
└── lib
320+
└── cmake
321+
└── beman.expected
322+
├── beman.expected-config.cmake
323+
├── beman.expected-config-version.cmake
324+
└── beman.expected-targets.cmake```

0 commit comments

Comments
 (0)