New read_constraint Wrapper
Adds a read_constraint wrapper that enables complex constraints to be defined within a glz::meta or using member functions. Parsing is short circuited upon violating a constraint and a nicely formatted error can be produced with a custom error message.
Example constraint violation outputs:
1:11: constraint_violated
{"age": -1, "name": "Victor"}
^ Age out of range
1:35: constraint_violated
{"age": 10, "name": "Abra Cadabra"}
^ Name is too long
Constraint code:
struct constrained_object
{
int age{};
std::string name{};
};
template <>
struct glz::meta<constrained_object>
{
using T = constrained_object;
static constexpr auto limit_age = [](const T&, int age) {
return (age >= 0 && age <= 120);
};
static constexpr auto limit_name = [](const T&, const std::string& name) {
return name.size() <= 8;
};
static constexpr auto value = object("age", read_constraint<&T::age, limit_age, "Age out of range">, //
"name", read_constraint<&T::name, limit_name, "Name is too long">);
};- Support for read constraints by @stephenberry in #1751
Improvements
- Update fast_float from 7.0.0 to 8.0.2 by @musicinmybrain in #1744
- Asio client get/set throwing helpers by @stephenberry in #1747
- Use std::move for custom reading by @stephenberry in #1748
- inout helper for asio_client by @stephenberry in #1752
Fixes
- Requires checks for custom_read and custom_write for objects by @stephenberry in #1756
- Glaze will now respect custom_read and custom_write booleans within
glz::metafor object types
- Glaze will now respect custom_read and custom_write booleans within
Full Changelog: v5.2.1...v5.3.0