Skip to content

Commit 0533312

Browse files
Added documentation
1 parent 8862ce5 commit 0533312

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ https://conan.io/center/recipes/reflect-cpp
554554
This will compile reflect-cpp with JSON support only. You can then include reflect-cpp in your project and link to the binary.
555555
556556
```bash
557-
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
557+
cmake -S . -B build -DCMAKE_CXX_STANDARD=20 -DCMAKE_BUILD_TYPE=Release
558558
cmake --build build -j 4 # gcc, clang
559559
cmake --build build --config Release -j 4 # MSVC
560560
```

benchmarks/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ this repository to learn how to install vcpkg.
1919
To compile the benchmarks, do the following:
2020

2121
```bash
22-
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DREFLECTCPP_BUILD_BENCHMARKS=ON
22+
cmake -S . -B build -DCMAKE_CXX_STANDARD=20 -DCMAKE_BUILD_TYPE=Release -DREFLECTCPP_BUILD_BENCHMARKS=ON
2323
cmake --build build -j 4 # gcc, clang
2424
cmake --build build --config Release -j 4 # MSVC
2525
```

docs/install.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Simply use [this recipe](https://conan.io/center/recipes/reflect-cpp).
4141
This will compile reflect-cpp with JSON support only. You can then include reflect-cpp in your project and link to the binary.
4242

4343
```bash
44-
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
44+
cmake -S . -B build -DCMAKE_CXX_STANDARD=20 -DCMAKE_BUILD_TYPE=Release
4545
cmake --build build -j 4 # gcc, clang
4646
cmake --build build --config Release -j 4 # MSVC
4747
```
@@ -66,6 +66,14 @@ git submodule update --init
6666
# You may be prompted to install additional dependencies.
6767
```
6868

69+
To compile the library:
70+
71+
```bash
72+
cmake -S . -B build -DCMAKE_CXX_STANDARD=20 -DREFLECTCPP_AVRO=ON -DREFLECTCPP_BSON=ON -DREFLECTCPP_CAPNPROTO=ON -DREFLECTCPP_CBOR=ON -DREFLECTCPP_FLEXBUFFERS=ON -DREFLECTCPP_MSGPACK=ON -DREFLECTCPP_XML=ON -DREFLECTCPP_TOML=ON -DREFLECTCPP_UBJSON=ON -DREFLECTCPP_YAML=ON -DCMAKE_BUILD_TYPE=Release
73+
cmake --build build -j 4 # gcc, clang
74+
cmake --build build --config Release -j 4 # MSVC
75+
```
76+
6977
To use reflect-cpp in your project:
7078

7179
```cmake
@@ -84,6 +92,7 @@ set(REFLECTCPP_YAML ON) # Optional
8492
target_link_libraries(your_project PRIVATE reflectcpp) # Link against the library
8593
```
8694

95+
8796
### Troubleshooting vcpkg
8897

8998
vcpkg is a great, but very ambitious and complex project (just like C++ is a great, but very ambitious and complex language). Here are some of the you might run into and how to resolve them:

docs/result.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ in C++-23. However, reflect-cpp is a library for C++-20 and until that changes,
3232
If you do not care about these objections to exceptions, you can just call `rfl::json::read<...>(json_string).value()`,
3333
which throws an exception, if the result type contains an error and be done with it.
3434

35+
**Note**: If you want to use `std::expected` instead of our own Result type, you can pass `-DREFLECTCPP_USE_STD_EXPECTED` during compilation.
36+
This requires C++-23 support and may not be supported on all C++ compilers.
37+
3538
## What is `rfl::Result`?
3639

3740
`rfl::Result` is similar to `std::optional` it that it contains an object that may or may not be there. However,
@@ -134,20 +137,18 @@ if (my_result) {
134137

135138
`rfl::error("error message")` is a simple utility function for `rfl::Unexpected<Error>(Error("error message"))`.
136139

137-
## `.and_other(...)`, `.or_else(...)`, `.or_other(...)`
138-
139-
`r1.and_other(r2)` expects an `r2` or type `rfl::Result<U>`. It returns an error, if `r1` contains an error and `r2` otherwise.
140+
## `.or_else(...)`, `.transform_error(...)`
140141

141142
`r.or_else(f)` expects a function `f` for type `Error -> rfl::Result<T>`. It returns `r` if `r` did not contain an error and the results of `f` otherwise.
142143

144+
`r.transform_error(f)` expects a function `f` for type `Error -> Error`.
145+
143146
This is often used to produce better error messages:
144147

145148
```cpp
146149
const auto embellish_error = [&](const Error& _e) -> rfl::Result<T> {
147150
return rfl::error("Failed to parse field '" + key + "': " + _e.what());
148151
};
149-
return Parser<T>::read(_r, &_var).or_else(embellish_error);
152+
return Parser<T>::read(_r, &_var).transform_error(embellish_error);
150153
```
151154

152-
`r1.or_other(r2)` expects an `r2` or type `rfl::Result<T>`. It returns an `r1`, if `r1` does not contain an error and `r2` otherwise.
153-

tests/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ git submodule update --init
1616
To compile the tests, do the following:
1717

1818
```bash
19-
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DREFLECTCPP_BUILD_TESTS=ON
19+
cmake -S . -B build -DCMAKE_CXX_STANDARD=20 -DCMAKE_BUILD_TYPE=Release -DREFLECTCPP_BUILD_TESTS=ON
2020
cmake --build build -j 4 # gcc, clang
2121
cmake --build build --config Release -j 4 # MSVC
2222
```
@@ -32,7 +32,7 @@ To run the tests, do the following:
3232
To compile the tests with serialization formats other than JSON, do the following:
3333

3434
```bash
35-
cmake -S . -B build -DREFLECTCPP_BUILD_TESTS=ON -DREFLECTCPP_AVRO=ON -DREFLECTCPP_BSON=ON -DREFLECTCPP_CAPNPROTO=ON -DREFLECTCPP_CBOR=ON -DREFLECTCPP_FLEXBUFFERS=ON -DREFLECTCPP_MSGPACK=ON -DREFLECTCPP_XML=ON -DREFLECTCPP_TOML=ON -DREFLECTCPP_UBJSON=ON -DREFLECTCPP_YAML=ON -DCMAKE_BUILD_TYPE=Release
35+
cmake -S . -B build -DCMAKE_CXX_STANDARD=20 -DREFLECTCPP_BUILD_TESTS=ON -DREFLECTCPP_AVRO=ON -DREFLECTCPP_BSON=ON -DREFLECTCPP_CAPNPROTO=ON -DREFLECTCPP_CBOR=ON -DREFLECTCPP_FLEXBUFFERS=ON -DREFLECTCPP_MSGPACK=ON -DREFLECTCPP_XML=ON -DREFLECTCPP_TOML=ON -DREFLECTCPP_UBJSON=ON -DREFLECTCPP_YAML=ON -DCMAKE_BUILD_TYPE=Release
3636
cmake --build build -j 4 # gcc, clang
3737
cmake --build build --config Release -j 4 # MSVC
3838
```

0 commit comments

Comments
 (0)