From 60bb1cf942ad0815dcf42cbfe8acd1e076d848cf Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 29 Oct 2019 22:04:40 +0900 Subject: Derive Omittable<> from std::optional<> That breaks API all over the place but: 1. The fixes are trivial. 2. More of std:: is used instead of home-baking the same stuff. --- lib/converters.h | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) (limited to 'lib/converters.h') diff --git a/lib/converters.h b/lib/converters.h index b753a80b..157bff27 100644 --- a/lib/converters.h +++ b/lib/converters.h @@ -206,7 +206,7 @@ template struct JsonConverter> { static QJsonValue dump(const Omittable& from) { - return from.omitted() ? QJsonValue() : toJson(from.value()); + return from.has_value() ? toJson(from.value()) : QJsonValue(); } static Omittable load(const QJsonValue& jv) { @@ -378,28 +378,10 @@ namespace _impl { static void impl(ContT& container, const QString& key, const OmittableT& value) { - if (!value.omitted()) - addTo(container, key, value.value()); + if (value) + addTo(container, key, *value); } }; - -#if 0 - // This is a special one that unfolds optional<> - template - struct AddNode, Force> - { - template - static void impl(ContT& container, - const QString& key, const OptionalT& value) - { - if (value) - AddNode::impl(container, key, value.value()); - else if (Force) // Edge case, no value but must put something - AddNode::impl(container, key, QString{}); - } - }; -#endif - } // namespace _impl static constexpr bool IfNotEmpty = false; -- cgit v1.2.3