-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Make opts use generic * fix glz::auto * Create opts_internal * opts_internal enum struct * Pulling options out of opts * Use consteval check functions * use check_hide_non_invocable * Use auto&& * check_allow_conversions * Update json_conformance.cpp * fix for GCC * GCC warning fixes * fix more GCC warnings * Move validate_skipped out of glz::opts * Fix GCC warnings * Create options.md * Update readme concerning compile time options * Move shrink_to_fit out of default opts * Move write_type_info out of default opts * Update README.md * Update feature_test.hpp
- Loading branch information
1 parent
e3ccdef
commit d5a872b
Showing
40 changed files
with
497 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Compile Time Options | ||
|
||
Glaze has a large number of available compile time options. These options are passed as a non-type template parameter to read/write calls. | ||
|
||
In order to keep template errors more succinct and allow more customization, Glaze allows users to build their own option structs. | ||
|
||
Example: | ||
|
||
```c++ | ||
struct custom_opts : glz::opts // Inherit from glz::opts to get basic options | ||
{ | ||
// Add known Glaze options that do not exist in the base glz::opts | ||
bool validate_trailing_whitespace = true; | ||
}; | ||
``` | ||
|
||
In use: | ||
|
||
```c++ | ||
// Using custom_opts while specifying a base option (prettify) | ||
glz::write<custom_opts{{glz::opts{.prettify = true}}, true}>(obj); | ||
``` | ||
## How Custom Options Work | ||
Glaze uses C++20 concepts to detect if an option exists in the provided options struct, if it doesn't exist, a default value is returned. | ||
```c++ | ||
// Code from Glaze demonstrating compile time option check: | ||
consteval bool check_validate_trailing_whitespace(auto&& Opts) { | ||
if constexpr (requires { Opts.validate_trailing_whitespace; }) { | ||
return Opts.validate_trailing_whitespace; | ||
} else { | ||
return false; // Default value (may be different for various options) | ||
} | ||
} | ||
``` | ||
|
||
## Available Options Outside of glz::opts | ||
|
||
In `glaze/core/opts.hpp` you can see the default provided fields in `glz::opts`. | ||
|
||
The supported, but not default provided options are listed after `glz::opts` and include: | ||
|
||
```c++ | ||
bool validate_skipped = false; | ||
// If full validation should be performed on skipped values | ||
|
||
bool validate_trailing_whitespace = false; | ||
// If, after parsing a value, we want to validate the trailing whitespace | ||
|
||
bool concatenate = true; | ||
// Concatenates ranges of std::pair into single objects when writing | ||
|
||
bool allow_conversions = true; | ||
// Whether conversions between convertible types are allowed in binary, e.g. double -> float | ||
|
||
bool write_type_info = true; | ||
// Write type info for meta objects in variants | ||
|
||
bool shrink_to_fit = false; | ||
// Shrinks dynamic containers to new size to save memory | ||
|
||
bool hide_non_invocable = true; | ||
// Hides non-invocable members from the cli_menu (may be applied elsewhere in the future) | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.