From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Fri, 3 Apr 2026 23:07:20 -0700 Subject: [PATCH 21/25] Add array constructor --- json.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/json.h b/json.h index 6a52615ab3e1799ebcf51a3b5ca445b1e2e64b97..ef3ea13b7cb147f0b383ff1ead496d495cfece32 100644 --- a/json.h +++ b/json.h @@ -17,6 +17,8 @@ #pragma once +#include +#include #include #include #include @@ -56,6 +58,19 @@ concept HasJsonDeserializer = requires (json& j, const json& cj, const T& val) { { json_serializer>::from(cj) } -> std::convertible_to>; }; +template +concept JsonConvertible = + HasToJson || + HasJsonSerializer || + std::is_same_v || + std::is_same_v || + std::is_floating_point_v || + std::is_integral_v || + std::convertible_to || + std::convertible_to || + std::is_same_v> || + std::is_same_v>; + template void apply_pairs_helper(F&& f, Tuple&& t, std::index_sequence) { // This fold expression creates a sequence of calls to f for each pair @@ -190,6 +205,12 @@ class json { } + template + requires detail::JsonConvertible> + json(const R& range) : type_(Type::Array), array_value(std::ranges::cbegin(range), std::ranges::cend(range)) + { + } + template json(const T& value) : type_(Type::Null) {