#pragma once #include "schema.hpp" #include #include #include namespace structive { struct Validation_Error { std::string_view property_key; std::string_view code; }; template std::optional validate_property_value(const Schema& schema, const Value& value) { std::optional error; schema.template property().for_each_constraint([&](const auto& constraint_value) { if (!error && !static_cast(constraint_value.validate(value))) { using constraint_type = std::remove_cvref_t; error = Validation_Error{declared_property_key>(), constraint_type::code.view()}; } }); return error; } template std::optional validate_property_value(const Schema& schema, const Value& value) requires Schema_Property_Member { return validate_property_value>(schema, value); } template std::optional validate_property_key_value(const Schema& schema, const Value& value) requires Schema_Property_Key { return validate_property_value>(schema, value); } }